From df9655e80a16e784a60dc3845cc638d282500a57 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 28 Nov 2025 17:54:48 +0800 Subject: [PATCH] input: Adjust blink cursor height. (#1704) --- crates/ui/src/input/element.rs | 19 ++++++++++++------- crates/ui/src/input/input.rs | 1 + crates/ui/src/input/state.rs | 3 +++ crates/ui/src/styled.rs | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index ab716d77..002086bd 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -1,20 +1,20 @@ use std::{ops::Range, rc::Rc}; use gpui::{ - fill, point, px, relative, size, App, Bounds, Corners, Element, ElementId, ElementInputHandler, - Entity, GlobalElementId, Half, HighlightStyle, Hitbox, Hsla, IntoElement, LayoutId, - MouseButton, MouseMoveEvent, Path, Pixels, Point, ShapedLine, SharedString, Size, Style, - TextRun, TextStyle, UnderlineStyle, Window, + App, Bounds, Corners, Element, ElementId, ElementInputHandler, Entity, GlobalElementId, Half, + HighlightStyle, Hitbox, Hsla, IntoElement, LayoutId, MouseButton, MouseMoveEvent, Path, Pixels, + Point, ShapedLine, SharedString, Size, Style, TextRun, TextStyle, UnderlineStyle, Window, fill, + point, px, relative, size, }; use ropey::Rope; use smallvec::SmallVec; use crate::{ - input::{blink_cursor::CURSOR_WIDTH, text_wrapper::LineLayout, RopeExt as _}, ActiveTheme as _, Colorize, PixelsExt, Root, + input::{RopeExt as _, blink_cursor::CURSOR_WIDTH, text_wrapper::LineLayout}, }; -use super::{mode::InputMode, InputState, LastLayout}; +use super::{InputState, LastLayout, mode::InputMode}; const BOTTOM_MARGIN_ROWS: usize = 3; pub(super) const RIGHT_MARGIN: Pixels = px(10.); @@ -222,7 +222,12 @@ impl TextElement { } // cursor bounds - let cursor_height = line_height; + let cursor_height = match state.size { + crate::Size::Large => 1., + crate::Size::Small => 0.75, + _ => 0.85, + } * line_height; + cursor_bounds = Some(Bounds::new( point( bounds.left() + cursor_pos.x + line_number_width + scroll_offset.x, diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index ba45faaf..28d1ae99 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -252,6 +252,7 @@ impl RenderOnce for Input { state.text_wrapper.set_font(font, font_size, cx); state.text_wrapper.prepare_if_need(&state.text, cx); state.disabled = self.disabled; + state.size = self.size; }); let state = self.state.read(cx); diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index b8a5a67d..e865f215 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -22,6 +22,7 @@ use super::{ TabSize, blink_cursor::BlinkCursor, change::Change, element::TextElement, mask_pattern::MaskPattern, mode::InputMode, number_input, text_wrapper::TextWrapper, }; +use crate::Size; use crate::actions::{SelectDown, SelectLeft, SelectRight, SelectUp}; use crate::input::movement::MoveDirection; use crate::input::{ @@ -286,6 +287,7 @@ pub struct InputState { pub(super) last_bounds: Option>, pub(super) last_selected_range: Option, pub(super) selecting: bool, + pub(super) size: Size, pub(super) disabled: bool, pub(super) masked: bool, pub(super) clean_on_escape: bool, @@ -408,6 +410,7 @@ impl InputState { hover_popover: None, hover_definition: HoverDefinition::default(), silent_replace_text: false, + size: Size::default(), _subscriptions, _context_menu_task: Task::ready(Ok(())), _pending_update: false, diff --git a/crates/ui/src/styled.rs b/crates/ui/src/styled.rs index de0027b4..3de2f733 100644 --- a/crates/ui/src/styled.rs +++ b/crates/ui/src/styled.rs @@ -340,7 +340,7 @@ impl Size { match self { Self::Large => px(16.), Self::Medium => px(12.), - Self::Small => px(6.), + Self::Small => px(8.), Self::XSmall => px(4.), _ => px(8.), }