mirror of https://github.com/lapce/lapce.git
1. Add the editor setting disable_single_click: Disable single-click … (#3494)
* 1. Add the editor setting disable_single_click: Disable single-click to open files. * rename
This commit is contained in:
parent
351cfa6cbc
commit
2b8bc95a6e
|
@ -5,6 +5,7 @@ modal = false
|
|||
color-theme = "Lapce Dark"
|
||||
icon-theme = "Lapce Codicons"
|
||||
custom-titlebar = true
|
||||
file-exploerer-double-click = false
|
||||
|
||||
[editor]
|
||||
font-family = "monospace"
|
||||
|
|
|
@ -604,6 +604,9 @@ pub enum InternalCommand {
|
|||
OpenFile {
|
||||
path: PathBuf,
|
||||
},
|
||||
OpenAndConfirmedFile {
|
||||
path: PathBuf,
|
||||
},
|
||||
OpenFileInNewTab {
|
||||
path: PathBuf,
|
||||
},
|
||||
|
|
|
@ -14,4 +14,8 @@ pub struct CoreConfig {
|
|||
desc = "Enable customised titlebar and disable OS native one (Linux, BSD, Windows)"
|
||||
)]
|
||||
pub custom_titlebar: bool,
|
||||
#[field_names(
|
||||
desc = "Only allow double-click to open files in the file explorer"
|
||||
)]
|
||||
pub file_exploerer_double_click: bool,
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
ffi::OsStr,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use floem::{
|
||||
|
@ -12,7 +13,7 @@
|
|||
ext_event::create_ext_action,
|
||||
keyboard::Modifiers,
|
||||
menu::{Menu, MenuItem},
|
||||
reactive::{RwSignal, Scope, SignalGet, SignalUpdate, SignalWith},
|
||||
reactive::{ReadSignal, RwSignal, Scope, SignalGet, SignalUpdate, SignalWith},
|
||||
views::editor::text::SystemClipboard,
|
||||
};
|
||||
use globset::Glob;
|
||||
|
@ -31,6 +32,7 @@
|
|||
|
||||
use crate::{
|
||||
command::{CommandExecuted, CommandKind, InternalCommand, LapceCommand},
|
||||
config::LapceConfig,
|
||||
editor::EditorData,
|
||||
keypress::{condition::Condition, KeyPressFocus},
|
||||
main_split::Editors,
|
||||
|
@ -394,10 +396,10 @@ pub fn cancel_naming(&self) {
|
|||
self.naming.set(Naming::None);
|
||||
}
|
||||
|
||||
pub fn click(&self, path: &Path) {
|
||||
pub fn click(&self, path: &Path, config: ReadSignal<Arc<LapceConfig>>) {
|
||||
if self.is_dir(path) {
|
||||
self.toggle_expand(path);
|
||||
} else {
|
||||
} else if !config.get_untracked().core.file_exploerer_double_click {
|
||||
self.common
|
||||
.internal_command
|
||||
.send(InternalCommand::OpenFile {
|
||||
|
@ -459,9 +461,20 @@ pub fn reveal_in_file_tree(&self, path: PathBuf) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn double_click(&self, path: &Path) -> EventPropagation {
|
||||
pub fn double_click(
|
||||
&self,
|
||||
path: &Path,
|
||||
config: ReadSignal<Arc<LapceConfig>>,
|
||||
) -> EventPropagation {
|
||||
if self.is_dir(path) {
|
||||
EventPropagation::Continue
|
||||
} else if config.get_untracked().core.file_exploerer_double_click {
|
||||
self.common.internal_command.send(
|
||||
InternalCommand::OpenAndConfirmedFile {
|
||||
path: path.to_path_buf(),
|
||||
},
|
||||
);
|
||||
EventPropagation::Stop
|
||||
} else {
|
||||
self.common
|
||||
.internal_command
|
||||
|
|
|
@ -401,7 +401,8 @@ fn file_explorer_view(
|
|||
},
|
||||
)
|
||||
}
|
||||
});
|
||||
})
|
||||
.debug_name("file item");
|
||||
|
||||
// Only handle click events if we are not naming the file node
|
||||
if let FileNodeViewKind::Path(path) = &kind {
|
||||
|
@ -411,13 +412,18 @@ fn file_explorer_view(
|
|||
let aux_click_path = path.clone();
|
||||
view.on_click_stop({
|
||||
let kind = kind.clone();
|
||||
let config = config.clone();
|
||||
move |_| {
|
||||
click_data.click(&click_path);
|
||||
click_data.click(&click_path, config);
|
||||
select.update(|x| *x = Some(kind.clone()));
|
||||
}
|
||||
})
|
||||
.on_double_click(move |_| {
|
||||
double_click_data.double_click(&double_click_path)
|
||||
.on_double_click({
|
||||
let config = config.clone();
|
||||
move |_| {
|
||||
double_click_data
|
||||
.double_click(&double_click_path, config)
|
||||
}
|
||||
})
|
||||
.on_secondary_click_stop(move |_| {
|
||||
secondary_click_data.secondary_click(&secondary_click_path);
|
||||
|
|
|
@ -1558,6 +1558,21 @@ pub fn run_internal_command(&self, cmd: InternalCommand) {
|
|||
None,
|
||||
);
|
||||
}
|
||||
InternalCommand::OpenAndConfirmedFile { path } => {
|
||||
self.main_split.jump_to_location(
|
||||
EditorLocation {
|
||||
path,
|
||||
position: None,
|
||||
scroll_offset: None,
|
||||
ignore_unconfirmed: false,
|
||||
same_editor_tab: false,
|
||||
},
|
||||
None,
|
||||
);
|
||||
if let Some(editor) = self.main_split.active_editor.get_untracked() {
|
||||
editor.confirmed.set(true);
|
||||
}
|
||||
}
|
||||
InternalCommand::OpenFileInNewTab { path } => {
|
||||
self.main_split.jump_to_location(
|
||||
EditorLocation {
|
||||
|
|
Loading…
Reference in New Issue