mirror of https://github.com/lapce/lapce.git
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:
parent
b462a43df9
commit
b92c519e29
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
@ -954,7 +967,7 @@ pub struct LapceConfig {
|
|||
icon_theme_list: im::Vector<String>,
|
||||
}
|
||||
impl LapceConfig {
|
||||
/// Get the dropdown information for the specific setting, used for the settings UI.
|
||||
/// Get the dropdown information for the specific setting, used for the settings UI.
|
||||
/// This should aim to efficiently return the data, because it is used to determine whether to
|
||||
/// update the dropdown items.
|
||||
pub fn get_dropdown_info(&self, kind: &str, key: &str) -> Option<DropdownInfo> {
|
||||
|
|
|
@ -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,52 +687,62 @@ 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 {
|
||||
if node.read {
|
||||
node.open = !node.open;
|
||||
} else {
|
||||
let tab_id = data.id;
|
||||
let event_sink = ctx.get_external_handle();
|
||||
FileExplorerData::read_dir(
|
||||
&node.path_buf,
|
||||
true,
|
||||
tab_id,
|
||||
&data.proxy,
|
||||
event_sink,
|
||||
);
|
||||
}
|
||||
let path = node.path_buf.clone();
|
||||
if let Some(paths) = file_explorer.node_tree(&path) {
|
||||
for path in paths.iter() {
|
||||
file_explorer.update_node_count(path);
|
||||
let cont_open = !(matches!(
|
||||
double_click_mode,
|
||||
ClickMode::DoubleClickAll
|
||||
) && mouse_event.count < 2);
|
||||
if cont_open {
|
||||
if node.read {
|
||||
node.open = !node.open;
|
||||
} else {
|
||||
let tab_id = data.id;
|
||||
let event_sink = ctx.get_external_handle();
|
||||
FileExplorerData::read_dir(
|
||||
&node.path_buf,
|
||||
true,
|
||||
tab_id,
|
||||
&data.proxy,
|
||||
event_sink,
|
||||
);
|
||||
}
|
||||
let path = node.path_buf.clone();
|
||||
if let Some(paths) = file_explorer.node_tree(&path) {
|
||||
for path in paths.iter() {
|
||||
file_explorer.update_node_count(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::OpenFile(
|
||||
node.path_buf.clone(),
|
||||
false,
|
||||
),
|
||||
Target::Widget(data.id),
|
||||
));
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::ActiveFileChanged {
|
||||
path: Some(node.path_buf.clone()),
|
||||
},
|
||||
Target::Widget(file_explorer.widget_id),
|
||||
));
|
||||
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(
|
||||
node.path_buf.clone(),
|
||||
false,
|
||||
),
|
||||
Target::Widget(data.id),
|
||||
));
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::ActiveFileChanged {
|
||||
path: Some(node.path_buf.clone()),
|
||||
},
|
||||
Target::Widget(file_explorer.widget_id),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue