mirror of
https://github.com/rust-kotlin/ashell.git
synced 2026-09-22 08:01:00 +00:00
fix: Cache text metrics for terminal IME bounds to prevent blocking during composition
This commit is contained in:
+7
-6
@@ -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),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user