Merge branch 'fix-modifier-toggling' into 'main'

input: Make it possible to deactivate a modifier with any button for it

Closes #433

See merge request World/Phosh/squeekboard!706
This commit is contained in:
Marge Bot
2024-11-19 12:21:51 +00:00
3 changed files with 7 additions and 5 deletions

View File

@ -1186,7 +1186,7 @@ mod seat {
key_id, key_id,
modifier, time, modifier, time,
), ),
false => submission.handle_drop_modifier(key_id, time), false => submission.handle_drop_modifier(key_id, modifier, time),
} }
} }
// only show when UI is present // only show when UI is present

View File

@ -220,7 +220,8 @@ impl Submission {
pub fn handle_add_modifier( pub fn handle_add_modifier(
&mut self, &mut self,
key_id: KeyStateId, key_id: KeyStateId,
modifier: Modifier, _time: Timestamp, modifier: Modifier,
_time: Timestamp,
) { ) {
self.modifiers_active.push((key_id, modifier)); self.modifiers_active.push((key_id, modifier));
self.update_modifiers(); self.update_modifiers();
@ -228,10 +229,11 @@ impl Submission {
pub fn handle_drop_modifier( pub fn handle_drop_modifier(
&mut self, &mut self,
key_id: KeyStateId, _key_id: KeyStateId,
modifier: Modifier,
_time: Timestamp, _time: Timestamp,
) { ) {
vec_remove(&mut self.modifiers_active, |(id, _)| *id == key_id); vec_remove(&mut self.modifiers_active, |(_, m)| *m == modifier);
self.update_modifiers(); self.update_modifiers();
} }

View File

@ -311,7 +311,7 @@ pub trait WarningHandler {
fn handle(&mut self, warning: &str); fn handle(&mut self, warning: &str);
} }
/// Removes the first matcing item /// Removes the first matching item
pub fn vec_remove<T, F: FnMut(&T) -> bool>(v: &mut Vec<T>, pred: F) -> Option<T> { pub fn vec_remove<T, F: FnMut(&T) -> bool>(v: &mut Vec<T>, pred: F) -> Option<T> {
let idx = v.iter().position(pred); let idx = v.iter().position(pred);
idx.map(|idx| v.remove(idx)) idx.map(|idx| v.remove(idx))