Hide the mouse when the user is typing in the editor (#25040)
Closes https://github.com/zed-industries/zed/issues/4461 This PR improves the coding experience by hiding the mouse while the user is typing so it does not accidentally get in their way, making it challenging to ready characters in the editor. Release Notes: - The following PR hides the cursor when the user is typing by adding a new cursor style called `None`. - Assuming the user does not move the mouse, it will stay hidden until it is moved again. https://github.com/user-attachments/assets/6ba9f2ee-b9f3-4595-81e4-e9d986da4a39 --------- Co-authored-by: Agus <agus@zed.dev> Co-authored-by: Peter Tripp <peter@zed.dev> Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
parent
3116850688
commit
a8610fbd13
17 changed files with 127 additions and 28 deletions
|
@ -716,6 +716,8 @@ pub struct Editor {
|
|||
toggle_fold_multiple_buffers: Task<()>,
|
||||
_scroll_cursor_center_top_bottom_task: Task<()>,
|
||||
serialize_selections: Task<()>,
|
||||
mouse_cursor_hidden: bool,
|
||||
hide_mouse_while_typing: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
|
||||
|
@ -1432,6 +1434,10 @@ impl Editor {
|
|||
serialize_selections: Task::ready(()),
|
||||
text_style_refinement: None,
|
||||
load_diff_task: load_uncommitted_diff,
|
||||
mouse_cursor_hidden: false,
|
||||
hide_mouse_while_typing: EditorSettings::get_global(cx)
|
||||
.hide_mouse_while_typing
|
||||
.unwrap_or(true),
|
||||
};
|
||||
this.tasks_update_task = Some(this.refresh_runnables(window, cx));
|
||||
this._subscriptions.extend(project_subscriptions);
|
||||
|
@ -2764,6 +2770,8 @@ impl Editor {
|
|||
return;
|
||||
}
|
||||
|
||||
self.mouse_cursor_hidden = self.hide_mouse_while_typing;
|
||||
|
||||
let selections = self.selections.all_adjusted(cx);
|
||||
let mut bracket_inserted = false;
|
||||
let mut edits = Vec::new();
|
||||
|
@ -14355,6 +14363,11 @@ impl Editor {
|
|||
self.scroll_manager.vertical_scroll_margin = editor_settings.vertical_scroll_margin;
|
||||
self.show_breadcrumbs = editor_settings.toolbar.breadcrumbs;
|
||||
self.cursor_shape = editor_settings.cursor_shape.unwrap_or_default();
|
||||
self.hide_mouse_while_typing = editor_settings.hide_mouse_while_typing.unwrap_or(true);
|
||||
|
||||
if !self.hide_mouse_while_typing {
|
||||
self.mouse_cursor_hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
if old_cursor_shape != self.cursor_shape {
|
||||
|
|
|
@ -37,6 +37,7 @@ pub struct EditorSettings {
|
|||
pub auto_signature_help: bool,
|
||||
pub show_signature_help_after_edits: bool,
|
||||
pub jupyter: Jupyter,
|
||||
pub hide_mouse_while_typing: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
|
@ -270,6 +271,10 @@ pub struct EditorSettingsContent {
|
|||
///
|
||||
/// Default: None
|
||||
pub cursor_shape: Option<CursorShape>,
|
||||
/// Determines whether the mouse cursor should be hidden while typing in an editor or input box.
|
||||
///
|
||||
/// Default: true
|
||||
pub hide_mouse_while_typing: Option<bool>,
|
||||
/// How to highlight the current line in the editor.
|
||||
///
|
||||
/// Default: all
|
||||
|
|
|
@ -848,6 +848,7 @@ impl EditorElement {
|
|||
let modifiers = event.modifiers;
|
||||
let gutter_hovered = gutter_hitbox.is_hovered(window);
|
||||
editor.set_gutter_hovered(gutter_hovered, cx);
|
||||
editor.mouse_cursor_hidden = false;
|
||||
|
||||
// Don't trigger hover popover if mouse is hovering over context menu
|
||||
if text_hitbox.is_hovered(window) {
|
||||
|
@ -4813,9 +4814,10 @@ impl EditorElement {
|
|||
bounds: layout.position_map.text_hitbox.bounds,
|
||||
}),
|
||||
|window| {
|
||||
let cursor_style = if self
|
||||
.editor
|
||||
.read(cx)
|
||||
let editor = self.editor.read(cx);
|
||||
let cursor_style = if editor.mouse_cursor_hidden {
|
||||
CursorStyle::None
|
||||
} else if editor
|
||||
.hovered_link_state
|
||||
.as_ref()
|
||||
.is_some_and(|hovered_link_state| !hovered_link_state.links.is_empty())
|
||||
|
@ -6815,6 +6817,7 @@ impl Element for EditorElement {
|
|||
},
|
||||
false,
|
||||
);
|
||||
|
||||
// Offset the content_bounds from the text_bounds by the gutter margin (which
|
||||
// is roughly half a character wide) to make hit testing work more like how we want.
|
||||
let content_origin =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue