Extended double-click options (#2127)

* include options for double-click functionality

* update changelog

* change int to enum values

* implemented ClickModes enum

* rename def

* simplify continue conditional

* rem extra brackets

---------

Co-authored-by: Jesse Stippel <jesse.stippel@umwerk-systems.com>
This commit is contained in:
Jesse Stippel 2023-02-21 14:35:08 +01:00 committed by GitHub
parent b462a43df9
commit b92c519e29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 40 deletions

View File

@ -26,6 +26,7 @@
- [#2071](https://github.com/lapce/lapce/pull/2071): Add command and keybinds to delete line
- [#2073](https://github.com/lapce/lapce/pull/2073): Add Ctrl+{a,e,k} keybinds on macOS
- [#2128](https://github.com/lapce/lapce/pull/2128): Add Lapce app icon to logo collection
- [#2127](https://github.com/lapce/lapce/pull/2127): Extended double-click options with file-only and file + folders mode
### Bug Fixes
- [#1911](https://github.com/lapce/lapce/pull/1911): Fix movement on selections with left/right arrow keys

View File

@ -44,7 +44,7 @@ multicursor-whole-words = true
render-whitespace = "none"
show-indent-guide = true
atomic-soft-tabs = false
double-click = false
double-click = "single"
move-focus-while-search = true
diff-context-lines=3
scroll-speed-modifier=1

View File

@ -317,6 +317,17 @@ impl LapceIcons {
pub const COMPLETION_ITEM_KIND_VARIABLE: &str = "completion_item_kind.variable";
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub enum ClickMode {
#[default]
#[serde(rename = "single")]
SingleClick,
#[serde(rename = "file")]
DoubleClickFile,
#[serde(rename = "all")]
DoubleClickAll,
}
pub trait GetConfig {
fn get_config(&self) -> &LapceConfig;
}
@ -467,8 +478,10 @@ pub struct EditorConfig {
desc = "If enabled the cursor treats leading soft tabs as if they are hard tabs."
)]
pub atomic_soft_tabs: bool,
#[field_names(desc = "Use double click to open interact with file explorer")]
pub double_click: bool,
#[field_names(
desc = "Use a double click to interact with the file explorer.\nOptions: single (default), file or all."
)]
pub double_click: ClickMode,
#[field_names(desc = "Move the focus as you type in the global search box")]
pub move_focus_while_search: bool,
#[field_names(

View File

@ -13,7 +13,7 @@
command::{
CommandKind, LapceCommand, LapceUICommand, LAPCE_COMMAND, LAPCE_UI_COMMAND,
},
config::{LapceConfig, LapceIcons, LapceTheme},
config::{ClickMode, LapceConfig, LapceIcons, LapceTheme},
data::{EditorTabChild, LapceData, LapceEditorData, LapceTabData},
document::{BufferContent, LocalBufferKind},
explorer::{FileExplorerData, Naming},
@ -687,17 +687,21 @@ fn event(
return;
}
let double_click_mode = data.config.editor.double_click.clone();
let file_explorer = Arc::make_mut(&mut data.file_explorer);
let index = ((mouse_event.pos.y + self.line_height)
/ self.line_height) as usize;
if mouse_event.button.is_left()
&& (!data.config.editor.double_click || mouse_event.count == 2)
{
if mouse_event.button.is_left() {
if let Some((_, node)) =
file_explorer.get_node_by_index_mut(index)
{
if node.is_dir {
let cont_open = !(matches!(
double_click_mode,
ClickMode::DoubleClickAll
) && mouse_event.count < 2);
if cont_open {
if node.read {
node.open = !node.open;
} else {
@ -717,7 +721,12 @@ fn event(
file_explorer.update_node_count(path);
}
}
}
} else {
let cont_open =
matches!(double_click_mode, ClickMode::SingleClick)
|| mouse_event.count > 1;
if cont_open {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::OpenFile(
@ -736,6 +745,7 @@ fn event(
}
}
}
}
if mouse_event.button.is_right() {
if let Some((indent_level, node)) = file_explorer