From fba6f24ab7b1106df9dd4eb8ed958476d08311c9 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Tue, 22 Mar 2022 16:14:32 -0700 Subject: [PATCH] Add editor lifetime events --- crates/editor/src/editor.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index d3e3f5ee5c..06b419dd9a 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -796,6 +796,8 @@ pub struct NavigationData { offset: usize, } +pub struct EditorCreated(pub ViewHandle); + impl Editor { pub fn single_line( field_editor_style: Option, @@ -932,6 +934,10 @@ impl Editor { cursor_shape: Default::default(), }; this.end_selection(cx); + + let editor_created_event = EditorCreated(cx.handle()); + cx.emit_global(editor_created_event); + this } @@ -5554,8 +5560,16 @@ pub enum Event { Closed, } +pub struct EditorFocused(pub ViewHandle); +pub struct EditorBlurred(pub ViewHandle); +pub struct EditorReleased(pub WeakViewHandle); + impl Entity for Editor { type Event = Event; + + fn release(&mut self, cx: &mut MutableAppContext) { + cx.emit_global(EditorReleased(self.handle.clone())); + } } impl View for Editor { @@ -5572,6 +5586,8 @@ impl View for Editor { } fn on_focus(&mut self, cx: &mut ViewContext) { + let focused_event = EditorFocused(cx.handle()); + cx.emit_global(focused_event); if let Some(rename) = self.pending_rename.as_ref() { cx.focus(&rename.editor); } else { @@ -5585,6 +5601,8 @@ impl View for Editor { } fn on_blur(&mut self, cx: &mut ViewContext) { + let blurred_event = EditorBlurred(cx.handle()); + cx.emit_global(blurred_event); self.focused = false; self.buffer .update(cx, |buffer, cx| buffer.remove_active_selections(cx));