From aba2b4d5ef7baba5bdd8939036f5778fccf6f438 Mon Sep 17 00:00:00 2001 From: Jakub Panek Date: Sun, 13 Aug 2023 13:43:25 +0200 Subject: [PATCH] fix: make modifiers configurable --- lapce-app/src/config/editor.rs | 40 ++++++++++++++++++++++++++++++++++ lapce-app/src/editor.rs | 36 ++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/lapce-app/src/config/editor.rs b/lapce-app/src/config/editor.rs index e3059bd6ab..39061e99bc 100644 --- a/lapce-app/src/config/editor.rs +++ b/lapce-app/src/config/editor.rs @@ -153,6 +153,46 @@ pub struct EditorConfig { desc = "Set the default number of visible lines above and below the diff block (-1 for infinite)" )] pub diff_context_lines: i32, + #[field_names(desc = "Multi-cursor key modifier.")] + pub multi_cursor_key_modifier: ModifierKeys, + #[field_names(desc = "Selection key modifier.")] + pub multi_select_key_modifier: ModifierKeys, +} + +type MultiCursorKeyModifier = ModifierKeys; + +impl Default for MultiCursorKeyModifier { + fn default() -> Self { + Self::Alt + } +} + +type MultiSelectKeyModifier = ModifierKeys; + +impl Default for MultiSelectKeyModifier { + fn default() -> Self { + Self::CtrlCmd + } +} + +enum ModifierKeys { + /// Maps to Alt on Windows/Linux and Option on macOS + Alt, + /// Maps to Control on Windows/Linux and to Command on macOS + CtrlCmd, +} + +impl Into for ModifierKeys { + fn into(self) -> keyboard_types::modifiers::Modifiers { + use floem::glazier::keyboard_types::modifiers::Modifiers; + match self { + ModifierKeys::Alt => Modifiers::ALT, + #[cfg(not(target_os = "macos"))] + ModifierKeys::CtrlCmd => Modifiers::CONTROL, + #[cfg(target_os = "macos")] + ModifierKeys::CtrlCmd => Modifiers::META, + } + } } impl EditorConfig { diff --git a/lapce-app/src/editor.rs b/lapce-app/src/editor.rs index 3fc3d6872d..c9812c5337 100644 --- a/lapce-app/src/editor.rs +++ b/lapce-app/src/editor.rs @@ -1882,8 +1882,22 @@ impl EditorData { cursor.add_region( start, end, - pointer_event.modifiers.contains(Modifiers::SHIFT), - pointer_event.modifiers.contains(Modifiers::ALT), + pointer_event.modifiers.contains( + self.common + .config + .get_untracked() + .editor + .multi_select_key_modifier + .into(), + ), + pointer_event.modifiers.contains( + self.common + .config + .get_untracked() + .editor + .multi_cursor_key_modifier + .into(), + ), ) }); } @@ -1899,8 +1913,22 @@ impl EditorData { cursor.add_region( start, end, - pointer_event.modifiers.contains(Modifiers::SHIFT), - pointer_event.modifiers.contains(Modifiers::ALT), + pointer_event.modifiers.contains( + self.common + .config + .get_untracked() + .editor + .multi_select_key_modifier + .into(), + ), + pointer_event.modifiers.contains( + self.common + .config + .get_untracked() + .editor + .multi_cursor_key_modifier + .into(), + ), ) }); }