mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-17 15:53:13 +00:00
Fix escape in GoToLine with new event emitter
This commit is contained in:
parent
27b3378020
commit
3c689ba33e
1 changed files with 12 additions and 13 deletions
|
@ -37,12 +37,6 @@ pub struct GoToLine {
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
|
||||||
Dismissed,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventEmitter<Event> for GoToLine {}
|
|
||||||
|
|
||||||
impl EventEmitter<ModalEvent> for GoToLine {}
|
impl EventEmitter<ModalEvent> for GoToLine {}
|
||||||
|
|
||||||
impl GoToLine {
|
impl GoToLine {
|
||||||
|
@ -78,7 +72,6 @@ impl GoToLine {
|
||||||
fn release(&mut self, cx: &mut WindowContext) {
|
fn release(&mut self, cx: &mut WindowContext) {
|
||||||
let scroll_position = self.prev_scroll_position.take();
|
let scroll_position = self.prev_scroll_position.take();
|
||||||
self.active_editor.update(cx, |editor, cx| {
|
self.active_editor.update(cx, |editor, cx| {
|
||||||
editor.focus(cx);
|
|
||||||
editor.highlight_rows(None);
|
editor.highlight_rows(None);
|
||||||
if let Some(scroll_position) = scroll_position {
|
if let Some(scroll_position) = scroll_position {
|
||||||
editor.set_scroll_position(scroll_position, cx);
|
editor.set_scroll_position(scroll_position, cx);
|
||||||
|
@ -95,7 +88,7 @@ impl GoToLine {
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
// todo!() this isn't working...
|
// 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),
|
editor::Event::BufferEdited { .. } => self.highlight_current_line(cx),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -130,22 +123,28 @@ impl GoToLine {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
||||||
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<Self>) {
|
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(point) = self.point_from_query(cx) {
|
if let Some(point) = self.point_from_query(cx) {
|
||||||
self.active_editor.update(cx, |active_editor, cx| {
|
self.active_editor.update(cx, |editor, cx| {
|
||||||
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
let snapshot = editor.snapshot(cx).display_snapshot;
|
||||||
let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
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])
|
s.select_ranges([point..point])
|
||||||
});
|
});
|
||||||
|
editor.focus(cx);
|
||||||
|
cx.notify();
|
||||||
});
|
});
|
||||||
self.prev_scroll_position.take();
|
self.prev_scroll_position.take();
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.emit(Event::Dismissed);
|
cx.emit(ModalEvent::Dismissed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue