diff options
author | 2025-02-03 17:12:08 +0100 | |
---|---|---|
committer | 2025-02-03 17:12:08 +0100 | |
commit | 141290c7402a4e087ce18d60b210f4feeafcebee (patch) | |
tree | e3225f5b2eada0c35156dbf5eef53f034e56f37c /core | |
parent | e8c680ce66b6b766a196e799b209e73e0bf416ab (diff) | |
download | iced-141290c7402a4e087ce18d60b210f4feeafcebee.tar.gz iced-141290c7402a4e087ce18d60b210f4feeafcebee.tar.bz2 iced-141290c7402a4e087ce18d60b210f4feeafcebee.zip |
Fix `InputMethod` conflicts with multiple scrollables
Diffstat (limited to 'core')
-rw-r--r-- | core/src/input_method.rs | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/core/src/input_method.rs b/core/src/input_method.rs index f10a1c3b..4e8c383b 100644 --- a/core/src/input_method.rs +++ b/core/src/input_method.rs @@ -82,21 +82,21 @@ pub enum Purpose { } 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; /// /// let open = InputMethod::Open { /// position: Point::ORIGIN, /// purpose: Purpose::Normal, - /// preedit: None, + /// preedit: Some(Preedit { content: "1".to_owned(), selection: None }), /// }; /// /// let open_2 = InputMethod::Open { /// position: Point::ORIGIN, /// purpose: Purpose::Secure, - /// preedit: None, + /// preedit: Some(Preedit { content: "2".to_owned(), selection: None }), /// }; /// /// let mut ime = InputMethod::Disabled; @@ -111,31 +111,47 @@ impl InputMethod { /// assert_eq!(ime, open); /// /// ime.merge(&open_2); - /// assert_eq!(ime, open_2); + /// assert_eq!(ime, open); /// ``` pub fn merge<T: AsRef<str>>(&mut self, other: &InputMethod<T>) { - match other { - InputMethod::None => {} - InputMethod::Open { + match (&self, other) { + (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, purpose, preedit, - } => { - *self = Self::Open { - position: *position, - purpose: *purpose, - 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; - } - _ => {} + } => InputMethod::Open { + position: *position, + purpose: *purpose, + preedit: preedit.as_ref().map(Preedit::to_owned), + }, } } } |