Estimate preedit position without calling layout_runs()

This commit is contained in:
KENZ 2025-05-02 07:01:55 +09:00 • committed by KENZ
parent 18462517f0
commit da57b9c12d

View file

@ -235,13 +235,31 @@ where
self self
} }
fn input_method<'b>(&self, state: &'b State, layout: Layout<'_>) -> InputMethod<&'b str> { fn input_method<'b>(
&self,
state: &'b State,
layout: Layout<'_>,
terminal: &std::sync::MutexGuard<'_, Terminal>,
) -> InputMethod<&'b str> {
if !state.is_focused { if !state.is_focused {
return InputMethod::Disabled; return InputMethod::Disabled;
} }
let view_position = layout.position() + [self.padding.left, self.padding.top].into();
// Draw cursor
let cursor = terminal.term.lock().renderable_content().cursor;
let col = cursor.point.column.0;
let line = cursor.point.line.0;
let width = terminal.size().cell_width;
let height = terminal.size().cell_height;
let bottom_left = view_position
+ Vector::new(
(col as f32 * width).floor(),
((line + 1) as f32 * height).floor(),
);
InputMethod::Enabled { InputMethod::Enabled {
cursor: Rectangle::default(), cursor: Rectangle::new(bottom_left, Size::default()),
purpose: input_method::Purpose::Normal, purpose: input_method::Purpose::Normal,
preedit: state.preedit.as_ref().map(input_method::Preedit::as_ref), preedit: state.preedit.as_ref().map(input_method::Preedit::as_ref),
} }
@ -892,7 +910,7 @@ where
shell.request_redraw(); shell.request_redraw();
} }
} }
shell.request_input_method(&self.input_method(state, layout)); shell.request_input_method(&self.input_method(state, layout, &terminal));
} }
cosmic::iced::window::Event::Unfocused => { cosmic::iced::window::Event::Unfocused => {
state.is_focused = false; state.is_focused = false;