Skip to content

Commit

Permalink
Extended double-click options (#2127)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Netroxen and Jesse Stippel committed Feb 21, 2023
1 parent b462a43 commit b92c519
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion defaults/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions lapce-data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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> {
Expand Down
82 changes: 46 additions & 36 deletions lapce-ui/src/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use lapce_data::{
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},
Expand Down Expand Up @@ -687,52 +687,62 @@ impl Widget<LapceTabData> for FileExplorerFileList {
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),
));
}
}
}
}
Expand Down

0 comments on commit b92c519

Please sign in to comment.