diff --git a/lapce-app/src/keymap.rs b/lapce-app/src/keymap.rs index 2cc6b2c6bc..9f7c371a4b 100644 --- a/lapce-app/src/keymap.rs +++ b/lapce-app/src/keymap.rs @@ -250,6 +250,9 @@ pub fn keymap_view(editors: Editors, common: Rc) -> impl View { }), )) .on_click_stop(move |_| { + if picker.keymap.get_untracked().is_some() { + return; + } let keymap = if let Some(keymap) = local_keymap.clone() { keymap } else { @@ -411,6 +414,7 @@ fn keyboard_picker_view( .padding_vert(1.0) .margin_right(5.0) .border(1.0) + .height(ui_line_height.get() as f32) .border_radius(6.0) .border_color( config.get().color(LapceColor::LAPCE_BORDER), @@ -424,7 +428,7 @@ fn keyboard_picker_view( .justify_center() .width_pct(100.0) .margin_top(20.0) - .height(ui_line_height.get() as f32 + 16.0) + .height((ui_line_height.get() as f32) * 1.2) .border(1.0) .border_radius(6.0) .border_color(config.color(LapceColor::LAPCE_BORDER)) @@ -518,18 +522,23 @@ fn keyboard_picker_view( .on_event_stop(EventListener::KeyDown, move |event| { if let Event::KeyDown(key_event) = event { if let Some(keypress) = KeyPressData::keypress(key_event) { - let keypress = keypress.keymap_press(); - picker.keys.update(|keys| { - if let Some((last_key, last_key_confirmed)) = keys.last() { - if !*last_key_confirmed && last_key.is_modifiers() { - keys.pop(); + if !keypress.filter_out_key() { + let keypress = keypress.keymap_press(); + picker.keys.update(|keys| { + if let Some((last_key, last_key_confirmed)) = keys.last() { + if keypress == *last_key { + return; + } + if !*last_key_confirmed && last_key.is_modifiers() { + keys.pop(); + } } - } - if keys.len() == 2 { - keys.clear(); - } - keys.push((keypress, false)); - }) + if keys.len() == 2 { + keys.clear(); + } + keys.push((keypress, false)); + }) + } } } }) @@ -548,7 +557,8 @@ fn keyboard_picker_view( .items_center() .justify_center() .apply_if(picker.keymap.with(|keymap| keymap.is_none()), |s| s.hide()) - }); + }) + .debug_name("keyboard picker"); let id = view.id(); create_effect(move |_| { diff --git a/lapce-app/src/keypress/press.rs b/lapce-app/src/keypress/press.rs index a598d274dd..0b6cd33d0d 100644 --- a/lapce-app/src/keypress/press.rs +++ b/lapce-app/src/keypress/press.rs @@ -1,4 +1,4 @@ -use floem::keyboard::Modifiers; +use floem::keyboard::{Key, Modifiers, NamedKey}; use super::{key::KeyInput, keymap::KeyMapPress}; @@ -16,4 +16,31 @@ impl KeyPress { mods: self.mods, } } + + pub fn only_shift(&self) -> bool { + if let KeyInput::Keyboard { + key_without_modifiers, + .. + } = &self.key + { + *key_without_modifiers == Key::Named(NamedKey::Shift) + } else { + false + } + } + + pub fn filter_out_key(&self) -> bool { + if let KeyInput::Keyboard { + key_without_modifiers, + .. + } = &self.key + { + *key_without_modifiers == Key::Named(NamedKey::Alt) + || *key_without_modifiers == Key::Named(NamedKey::Control) + || (*key_without_modifiers == Key::Named(NamedKey::Shift) + && !self.mods.contains(Modifiers::SHIFT)) + } else { + false + } + } }