Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make modifiers configurable #2544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions lapce-app/src/config/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<floem::glazier::keyboard_types::modifiers::Modifiers> 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 {
Expand Down
36 changes: 32 additions & 4 deletions lapce-app/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)
});
}
Expand All @@ -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(),
),
)
});
}
Expand Down