Fix InputMethod conflicts with multiple scrollables
This commit is contained in:
parent
e8c680ce66
commit
141290c740
2 changed files with 48 additions and 28 deletions
|
|
@ -82,21 +82,21 @@ pub enum Purpose {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputMethod {
|
impl InputMethod {
|
||||||
/// Merges two [`InputMethod`] strategies, prioritizing the second one when both ready:
|
/// Merges two [`InputMethod`] strategies, prioritizing the first one when both open:
|
||||||
/// ```
|
/// ```
|
||||||
/// # use iced_core::input_method::{InputMethod, Purpose};
|
/// # use iced_core::input_method::{InputMethod, Purpose, Preedit};
|
||||||
/// # use iced_core::Point;
|
/// # use iced_core::Point;
|
||||||
///
|
///
|
||||||
/// let open = InputMethod::Open {
|
/// let open = InputMethod::Open {
|
||||||
/// position: Point::ORIGIN,
|
/// position: Point::ORIGIN,
|
||||||
/// purpose: Purpose::Normal,
|
/// purpose: Purpose::Normal,
|
||||||
/// preedit: None,
|
/// preedit: Some(Preedit { content: "1".to_owned(), selection: None }),
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let open_2 = InputMethod::Open {
|
/// let open_2 = InputMethod::Open {
|
||||||
/// position: Point::ORIGIN,
|
/// position: Point::ORIGIN,
|
||||||
/// purpose: Purpose::Secure,
|
/// purpose: Purpose::Secure,
|
||||||
/// preedit: None,
|
/// preedit: Some(Preedit { content: "2".to_owned(), selection: None }),
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let mut ime = InputMethod::Disabled;
|
/// let mut ime = InputMethod::Disabled;
|
||||||
|
|
@ -111,31 +111,47 @@ impl InputMethod {
|
||||||
/// assert_eq!(ime, open);
|
/// assert_eq!(ime, open);
|
||||||
///
|
///
|
||||||
/// ime.merge(&open_2);
|
/// ime.merge(&open_2);
|
||||||
/// assert_eq!(ime, open_2);
|
/// assert_eq!(ime, open);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn merge<T: AsRef<str>>(&mut self, other: &InputMethod<T>) {
|
pub fn merge<T: AsRef<str>>(&mut self, other: &InputMethod<T>) {
|
||||||
match other {
|
match (&self, other) {
|
||||||
InputMethod::None => {}
|
(InputMethod::Open { .. }, _)
|
||||||
InputMethod::Open {
|
| (
|
||||||
|
InputMethod::Allowed,
|
||||||
|
InputMethod::None | InputMethod::Disabled,
|
||||||
|
)
|
||||||
|
| (InputMethod::Disabled, InputMethod::None) => {}
|
||||||
|
_ => {
|
||||||
|
*self = other.to_owned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the [`InputMethod`] is open.
|
||||||
|
pub fn is_open(&self) -> bool {
|
||||||
|
matches!(self, Self::Open { .. })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> InputMethod<T> {
|
||||||
|
/// Turns an [`InputMethod`] into its owned version.
|
||||||
|
pub fn to_owned(&self) -> InputMethod
|
||||||
|
where
|
||||||
|
T: AsRef<str>,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Self::None => InputMethod::None,
|
||||||
|
Self::Disabled => InputMethod::Disabled,
|
||||||
|
Self::Allowed => InputMethod::Allowed,
|
||||||
|
Self::Open {
|
||||||
position,
|
position,
|
||||||
purpose,
|
purpose,
|
||||||
preedit,
|
preedit,
|
||||||
} => {
|
} => InputMethod::Open {
|
||||||
*self = Self::Open {
|
position: *position,
|
||||||
position: *position,
|
purpose: *purpose,
|
||||||
purpose: *purpose,
|
preedit: preedit.as_ref().map(Preedit::to_owned),
|
||||||
preedit: preedit.as_ref().map(Preedit::to_owned),
|
},
|
||||||
};
|
|
||||||
}
|
|
||||||
InputMethod::Allowed
|
|
||||||
if matches!(self, Self::None | Self::Disabled) =>
|
|
||||||
{
|
|
||||||
*self = Self::Allowed;
|
|
||||||
}
|
|
||||||
InputMethod::Disabled if matches!(self, Self::None) => {
|
|
||||||
*self = Self::Disabled;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -727,6 +727,8 @@ where
|
||||||
_ => mouse::Cursor::Unavailable,
|
_ => mouse::Cursor::Unavailable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let had_input_method = shell.input_method().is_open();
|
||||||
|
|
||||||
let translation =
|
let translation =
|
||||||
state.translation(self.direction, bounds, content_bounds);
|
state.translation(self.direction, bounds, content_bounds);
|
||||||
|
|
||||||
|
|
@ -745,10 +747,12 @@ where
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if let InputMethod::Open { position, .. } =
|
if !had_input_method {
|
||||||
shell.input_method_mut()
|
if let InputMethod::Open { position, .. } =
|
||||||
{
|
shell.input_method_mut()
|
||||||
*position = *position + translation;
|
{
|
||||||
|
*position = *position + translation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue