From 0062cc000b825e3437221b408f826b7288638086 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 19 Jan 2024 02:54:52 -0500 Subject: [PATCH 1/2] Allow cursors to be shown via a command --- assets/keymaps/default.json | 3 ++- crates/editor/src/actions.rs | 1 + crates/editor/src/editor.rs | 30 +++++++++++++++++++----------- crates/editor/src/element.rs | 1 + 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index f18cc2a111ec432a283f9f08f3fd1acecdddda52..c4cfed2916cf7a44d63a4fe212f66001b5879aed 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -349,7 +349,8 @@ "alt-cmd-]": "editor::UnfoldLines", "ctrl-space": "editor::ShowCompletions", "cmd-.": "editor::ToggleCodeActions", - "alt-cmd-r": "editor::RevealInFinder" + "alt-cmd-r": "editor::RevealInFinder", + "ctrl-cmd-c": "editor::ShowCursors" } }, { diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index 9532bb642d85b15ae5cd8edf68e2338b1cefa174..dd489c039398b21cc5148884f0d8742558fa03f8 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -214,5 +214,6 @@ gpui::actions!( Undo, UndoSelection, UnfoldLines, + ShowCursors ] ); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 8876feeceff1daf1dfb85277d2cd958f1051544d..3b7b99cb82e66a931e39737d9ba85116c87ff176 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3899,6 +3899,24 @@ impl Editor { self.update_visible_copilot_suggestion(cx); } + pub fn show_cursors(&mut self, _: &ShowCursors, cx: &mut ViewContext) { + self.display_cursors(cx); + } + + fn display_cursors(&mut self, cx: &mut ViewContext) { + self.recently_focused = true; + cx.notify(); + cx.spawn(|this, mut cx| async move { + cx.background_executor().timer(Duration::from_secs(2)).await; + this.update(&mut cx, |this, cx| { + this.recently_focused = false; + cx.notify() + }) + .ok() + }) + .detach(); + } + fn next_copilot_suggestion(&mut self, _: &copilot::NextSuggestion, cx: &mut ViewContext) { if self.has_active_copilot_suggestion(cx) { self.cycle_copilot_suggestions(Direction::Next, cx); @@ -9003,17 +9021,7 @@ impl Editor { cx.focus(&rename_editor_focus_handle); } else { self.blink_manager.update(cx, BlinkManager::enable); - self.recently_focused = true; - cx.notify(); - cx.spawn(|this, mut cx| async move { - cx.background_executor().timer(Duration::from_secs(2)).await; - this.update(&mut cx, |this, cx| { - this.recently_focused = false; - cx.notify() - }) - .ok() - }) - .detach(); + self.display_cursors(cx); self.buffer.update(cx, |buffer, cx| { buffer.finalize_last_transaction(cx); if self.leader_peer_id.is_none() { diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 6c6bfba190c70b6aac155783a312cbb5af4f31a0..2f7afe2d06e44ee1f9539fbc2064ac7bdc73c5dc 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -327,6 +327,7 @@ impl EditorElement { register_action(view, cx, Editor::context_menu_prev); register_action(view, cx, Editor::context_menu_next); register_action(view, cx, Editor::context_menu_last); + register_action(view, cx, Editor::show_cursors); } fn register_key_listeners(&self, cx: &mut WindowContext) { From bcc13e151cc92e9af11ba4438499c88eff694388 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 19 Jan 2024 07:52:28 -0500 Subject: [PATCH 2/2] Change struct field name --- crates/editor/src/editor.rs | 8 ++++---- crates/editor/src/element.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 3b7b99cb82e66a931e39737d9ba85116c87ff176..7de6a69f1187ca97ab70aa0a5d6b808701adf329 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -367,7 +367,7 @@ pub struct Editor { project: Option>, collaboration_hub: Option>, blink_manager: Model, - recently_focused: bool, + display_cursors: bool, hovered_cursor: Option, pub show_local_selections: bool, mode: EditorMode, @@ -1613,7 +1613,7 @@ impl Editor { pixel_position_of_newest_cursor: None, gutter_width: Default::default(), style: None, - recently_focused: false, + display_cursors: false, hovered_cursor: Default::default(), editor_actions: Default::default(), show_copilot_suggestions: mode == EditorMode::Full, @@ -3904,12 +3904,12 @@ impl Editor { } fn display_cursors(&mut self, cx: &mut ViewContext) { - self.recently_focused = true; + self.display_cursors = true; cx.notify(); cx.spawn(|this, mut cx| async move { cx.background_executor().timer(Duration::from_secs(2)).await; this.update(&mut cx, |this, cx| { - this.recently_focused = false; + this.display_cursors = false; cx.notify() }) .ok() diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 2f7afe2d06e44ee1f9539fbc2064ac7bdc73c5dc..adb82b492c499668cdb237e6930d9831259e1ba9 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1999,7 +1999,7 @@ impl EditorElement { if Some(selection.peer_id) == editor.leader_peer_id { continue; } - let is_shown = editor.recently_focused || editor.hovered_cursor.as_ref().is_some_and(|c| c.replica_id == selection.replica_id && c.selection_id == selection.selection.id); + let is_shown = editor.display_cursors || editor.hovered_cursor.as_ref().is_some_and(|c| c.replica_id == selection.replica_id && c.selection_id == selection.selection.id); remote_selections .entry(selection.replica_id)