fix: Cache text metrics for terminal IME bounds to prevent blocking during composition

This commit is contained in:
TomZz
2026-06-12 20:20:49 +08:00
parent 8c24eb885c
commit aca03c924f
2 changed files with 12 additions and 7 deletions
+7 -6
View File
@@ -2792,19 +2792,20 @@ impl Ashell {
&self,
range_utf16: Range<usize>,
element_bounds: Bounds<Pixels>,
window: &Window,
cell_width: f32,
line_height: f32,
) -> Option<Bounds<Pixels>> {
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),
),
))
}
+5 -1
View File
@@ -144,6 +144,8 @@ pub struct PrepaintState {
struct TerminalInputHandler {
view: Entity<Ashell>,
element_bounds: Bounds<Pixels>,
cell_width: f32,
line_height: f32,
}
impl InputHandler for TerminalInputHandler {
@@ -219,7 +221,7 @@ impl InputHandler for TerminalInputHandler {
) -> Option<Bounds<Pixels>> {
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,
);