diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rs index c65373e6ac..8f0d94f3e8 100644 --- a/crates/go_to_line2/src/go_to_line.rs +++ b/crates/go_to_line2/src/go_to_line.rs @@ -37,12 +37,6 @@ pub struct GoToLine { _subscriptions: Vec, } -pub enum Event { - Dismissed, -} - -impl EventEmitter for GoToLine {} - impl EventEmitter for GoToLine {} impl GoToLine { @@ -78,7 +72,6 @@ impl GoToLine { fn release(&mut self, cx: &mut WindowContext) { let scroll_position = self.prev_scroll_position.take(); self.active_editor.update(cx, |editor, cx| { - editor.focus(cx); editor.highlight_rows(None); if let Some(scroll_position) = scroll_position { editor.set_scroll_position(scroll_position, cx); @@ -95,7 +88,7 @@ impl GoToLine { ) { match event { // todo!() this isn't working... - editor::Event::Blurred => cx.emit(Event::Dismissed), + editor::Event::Blurred => cx.emit(ModalEvent::Dismissed), editor::Event::BufferEdited { .. } => self.highlight_current_line(cx), _ => {} } @@ -130,22 +123,28 @@ impl GoToLine { } fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext) { - cx.emit(Event::Dismissed); + self.active_editor.update(cx, |editor, cx| { + editor.focus(cx); + cx.notify(); + }); + cx.emit(ModalEvent::Dismissed); } fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext) { if let Some(point) = self.point_from_query(cx) { - self.active_editor.update(cx, |active_editor, cx| { - let snapshot = active_editor.snapshot(cx).display_snapshot; + self.active_editor.update(cx, |editor, cx| { + let snapshot = editor.snapshot(cx).display_snapshot; let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left); - active_editor.change_selections(Some(Autoscroll::center()), cx, |s| { + editor.change_selections(Some(Autoscroll::center()), cx, |s| { s.select_ranges([point..point]) }); + editor.focus(cx); + cx.notify(); }); self.prev_scroll_position.take(); } - cx.emit(Event::Dismissed); + cx.emit(ModalEvent::Dismissed); } }