Skip to content

Commit

Permalink
Optimize shortcut key settings: 1.filter out alt/ctrl/shift
Browse files Browse the repository at this point in the history
2. filter out duplicate
3. adjust some styles.
  • Loading branch information
jm-observer committed Aug 14, 2024
1 parent 5f58268 commit 6c1c4c6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
36 changes: 23 additions & 13 deletions lapce-app/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ pub fn keymap_view(editors: Editors, common: Rc<CommonData>) -> 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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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))
Expand Down Expand Up @@ -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));
})
}
}
}
})
Expand All @@ -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 |_| {
Expand Down
29 changes: 28 additions & 1 deletion lapce-app/src/keypress/press.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use floem::keyboard::Modifiers;
use floem::keyboard::{Key, Modifiers, NamedKey};

use super::{key::KeyInput, keymap::KeyMapPress};

Expand All @@ -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
}
}
}

0 comments on commit 6c1c4c6

Please sign in to comment.