Skip to content

Commit

Permalink
Fix candidate window position for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 6, 2025
1 parent 4bbb5cb commit 4108dd0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
17 changes: 11 additions & 6 deletions core/src/input_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ pub enum InputMethod<T = String> {
/// No input method is allowed.
Disabled,
/// Input methods are allowed, but not open yet.
Allowed,
Allowed {
/// The position at which the input method dialog should be placed.
position: Point,
},
/// Input method is open.
Open {
/// The position at which the input method dialog should be placed.
Expand Down Expand Up @@ -101,11 +104,11 @@ impl InputMethod {
///
/// let mut ime = InputMethod::Disabled;
///
/// ime.merge(&InputMethod::<String>::Allowed);
/// assert_eq!(ime, InputMethod::Allowed);
/// ime.merge(&InputMethod::<String>::Allowed { position: Point::ORIGIN });
/// assert_eq!(ime, InputMethod::Allowed{ position: Point::ORIGIN });
///
/// ime.merge(&InputMethod::<String>::Disabled);
/// assert_eq!(ime, InputMethod::Allowed);
/// assert_eq!(ime, InputMethod::Allowed{ position: Point::ORIGIN });
///
/// ime.merge(&open);
/// assert_eq!(ime, open);
Expand All @@ -117,7 +120,7 @@ impl InputMethod {
match (&self, other) {
(InputMethod::Open { .. }, _)
| (
InputMethod::Allowed,
InputMethod::Allowed { .. },
InputMethod::None | InputMethod::Disabled,
)
| (InputMethod::Disabled, InputMethod::None) => {}
Expand All @@ -142,7 +145,9 @@ impl<T> InputMethod<T> {
match self {
Self::None => InputMethod::None,
Self::Disabled => InputMethod::Disabled,
Self::Allowed => InputMethod::Allowed,
Self::Allowed { position } => InputMethod::Allowed {
position: *position,
},
Self::Open {
position,
purpose,
Expand Down
8 changes: 4 additions & 4 deletions widget/src/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ where
return InputMethod::Disabled;
};

let Some(preedit) = &state.preedit else {
return InputMethod::Allowed;
};

let bounds = layout.bounds();
let internal = self.content.0.borrow_mut();

Expand All @@ -363,6 +359,10 @@ where
let position =
cursor + translation + Vector::new(0.0, f32::from(line_height));

let Some(preedit) = &state.preedit else {
return InputMethod::Allowed { position };
};

InputMethod::Open {
position,
purpose: input_method::Purpose::Normal,
Expand Down
11 changes: 6 additions & 5 deletions widget/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,6 @@ where
return InputMethod::Disabled;
};

let Some(preedit) = &state.is_ime_open else {
return InputMethod::Allowed;
};

let secure_value = self.is_secure.then(|| value.secure());
let value = secure_value.as_ref().unwrap_or(value);

Expand All @@ -432,9 +428,14 @@ where

let x = (text_bounds.x + cursor_x).floor() - scroll_offset
+ alignment_offset;
let position = Point::new(x, text_bounds.y + text_bounds.height);

let Some(preedit) = &state.is_ime_open else {
return InputMethod::Allowed { position };
};

InputMethod::Open {
position: Point::new(x, text_bounds.y + text_bounds.height),
position,
purpose: if self.is_secure {
input_method::Purpose::Secure
} else {
Expand Down
12 changes: 6 additions & 6 deletions winit/src/program/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,13 @@ where
InputMethod::Disabled => {
self.raw.set_ime_allowed(false);
}
InputMethod::Allowed | InputMethod::Open { .. } => {
InputMethod::Allowed { position }
| InputMethod::Open { position, .. } => {
self.raw.set_ime_allowed(true);
self.raw.set_ime_cursor_area(
LogicalPosition::new(position.x, position.y),
LogicalSize::new(10, 10), // TODO?
);
}
}

Expand All @@ -221,11 +226,6 @@ where
preedit,
} = input_method
{
self.raw.set_ime_cursor_area(
LogicalPosition::new(position.x, position.y),
LogicalSize::new(10, 10), // TODO?
);

self.raw.set_ime_purpose(conversion::ime_purpose(purpose));

if let Some(preedit) = preedit {
Expand Down

0 comments on commit 4108dd0

Please sign in to comment.