From aca03c924fbc96a0cc4a504c4414dc5cc85ea5ab Mon Sep 17 00:00:00 2001 From: TomZz Date: Fri, 12 Jun 2026 20:20:49 +0800 Subject: [PATCH] fix: Cache text metrics for terminal IME bounds to prevent blocking during composition --- src/main.rs | 13 +++++++------ src/terminal_element.rs | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9c5deac..2d4786e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2792,19 +2792,20 @@ impl Ashell { &self, range_utf16: Range, element_bounds: Bounds, - window: &Window, + cell_width: f32, + line_height: f32, ) -> Option> { let snapshot = self.active_snapshot()?; let cursor = snapshot.cursor?; let x = element_bounds.origin.x - + px(self.terminal_cell_width(window)) * cursor.col as f32 - + px(self.terminal_cell_width(window)) * range_utf16.start as f32; - let y = element_bounds.origin.y + px(self.terminal_line_height()) * cursor.row as f32; + + px(cell_width) * cursor.col as f32 + + px(cell_width) * range_utf16.start as f32; + let y = element_bounds.origin.y + px(line_height) * cursor.row as f32; Some(Bounds::new( point(x, y), size( - px(self.terminal_cell_width(window)), - px(self.terminal_line_height()), + px(cell_width), + px(line_height), ), )) } diff --git a/src/terminal_element.rs b/src/terminal_element.rs index 780f135..ecec7e7 100644 --- a/src/terminal_element.rs +++ b/src/terminal_element.rs @@ -144,6 +144,8 @@ pub struct PrepaintState { struct TerminalInputHandler { view: Entity, element_bounds: Bounds, + cell_width: f32, + line_height: f32, } impl InputHandler for TerminalInputHandler { @@ -219,7 +221,7 @@ impl InputHandler for TerminalInputHandler { ) -> Option> { self.view .read(cx) - .terminal_ime_bounds_for_range(range_utf16, self.element_bounds, _window) + .terminal_ime_bounds_for_range(range_utf16, self.element_bounds, self.cell_width, self.line_height) } fn character_index_for_point( @@ -492,6 +494,8 @@ impl Element for TerminalElement { TerminalInputHandler { view: self.view.clone(), element_bounds: prepaint.bounds, + cell_width: prepaint.metrics.cell_width.as_f32(), + line_height: prepaint.metrics.line_height.as_f32(), }, cx, );