From 3315fd94d27fde9f4d327ce6a8c4a009fd605505 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Mon, 1 Sep 2025 11:21:55 +0300 Subject: [PATCH] editor: Add an option to disable rounded corners for text selection (#36987) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #19891 Similar to VSCode’s `editor.roundedSelection` option. #### Before/after
Enabled (default)Disabled
Editor-based UIsimage imageimage image
Terminalimageimage
Release Notes: - Added setting `rounded_selection` to disable rounded corners for text selection. --- assets/settings/default.json | 2 ++ crates/editor/src/editor_settings.rs | 6 ++++++ crates/editor/src/element.rs | 9 +++++++-- crates/terminal_view/src/terminal_element.rs | 9 +++++++-- docs/src/configuring-zed.md | 6 ++++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index b15eb6e5ce8de85bb088108f065a31494b9087a1..2aec3aa7b9d56b3a04d2c8d1f80bb0d37c91b8cc 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -223,6 +223,8 @@ "current_line_highlight": "all", // Whether to highlight all occurrences of the selected text in an editor. "selection_highlight": true, + // Whether the text selection should have rounded corners. + "rounded_selection": true, // The debounce delay before querying highlights from the language // server based on the current cursor location. "lsp_highlight_debounce": 75, diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index c2baa9de024b1988f9acb77a529936f947103f56..084c4eb5c618cbf3d290b317b0035f1b8f307b3f 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -17,6 +17,7 @@ pub struct EditorSettings { pub cursor_shape: Option, pub current_line_highlight: CurrentLineHighlight, pub selection_highlight: bool, + pub rounded_selection: bool, pub lsp_highlight_debounce: u64, pub hover_popover_enabled: bool, pub hover_popover_delay: u64, @@ -441,6 +442,10 @@ pub struct EditorSettingsContent { /// /// Default: true pub selection_highlight: Option, + /// Whether the text selection should have rounded corners. + /// + /// Default: true + pub rounded_selection: Option, /// The debounce delay before querying highlights from the language /// server based on the current cursor location. /// @@ -794,6 +799,7 @@ impl Settings for EditorSettings { "editor.selectionHighlight", &mut current.selection_highlight, ); + vscode.bool_setting("editor.roundedSelection", &mut current.rounded_selection); vscode.bool_setting("editor.hover.enabled", &mut current.hover_popover_enabled); vscode.u64_setting("editor.hover.delay", &mut current.hover_popover_delay); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index ca6eac080e6121880eae63b4dc60ca6d32c6da5d..f384afa1ae988d8d224f9ec3de70932543519571 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -6063,7 +6063,7 @@ impl EditorElement { }; self.paint_lines_background(layout, window, cx); - let invisible_display_ranges = self.paint_highlights(layout, window); + let invisible_display_ranges = self.paint_highlights(layout, window, cx); self.paint_document_colors(layout, window); self.paint_lines(&invisible_display_ranges, layout, window, cx); self.paint_redactions(layout, window); @@ -6085,6 +6085,7 @@ impl EditorElement { &mut self, layout: &mut EditorLayout, window: &mut Window, + cx: &mut App, ) -> SmallVec<[Range; 32]> { window.paint_layer(layout.position_map.text_hitbox.bounds, |window| { let mut invisible_display_ranges = SmallVec::<[Range; 32]>::new(); @@ -6101,7 +6102,11 @@ impl EditorElement { ); } - let corner_radius = 0.15 * layout.position_map.line_height; + let corner_radius = if EditorSettings::get_global(cx).rounded_selection { + 0.15 * layout.position_map.line_height + } else { + Pixels::ZERO + }; for (player_color, selections) in &layout.selections { for selection in selections.iter() { diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 56715b604eeffe0b42302adcdf0d6fdd93919879..5bbf5ad36b3de89514d92ce9e305988817cec32f 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -1,4 +1,4 @@ -use editor::{CursorLayout, HighlightedRange, HighlightedRangeLine}; +use editor::{CursorLayout, EditorSettings, HighlightedRange, HighlightedRangeLine}; use gpui::{ AbsoluteLength, AnyElement, App, AvailableSpace, Bounds, ContentMask, Context, DispatchPhase, Element, ElementId, Entity, FocusHandle, Font, FontFeatures, FontStyle, FontWeight, @@ -1257,12 +1257,17 @@ impl Element for TerminalElement { if let Some((start_y, highlighted_range_lines)) = to_highlighted_range_lines(relative_highlighted_range, layout, origin) { + let corner_radius = if EditorSettings::get_global(cx).rounded_selection { + 0.15 * layout.dimensions.line_height + } else { + Pixels::ZERO + }; let hr = HighlightedRange { start_y, line_height: layout.dimensions.line_height, lines: highlighted_range_lines, color: *color, - corner_radius: 0.15 * layout.dimensions.line_height, + corner_radius: corner_radius, }; hr.paint(true, bounds, window); } diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index 2b1d801f8010c8ad00f1295c38803bd80df1c282..e245b3ca2facecb097b315f28d98ef2ea5a20048 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -685,6 +685,12 @@ List of `string` values - Setting: `selection_highlight` - Default: `true` +## Rounded Selection + +- Description: Whether the text selection should have rounded corners. +- Setting: `rounded_selection` +- Default: `true` + ## Cursor Blink - Description: Whether or not the cursor blinks.