Skip to content

Commit 7d5fb79

Browse files
committed
Handle single click to open on release, fixes #1212
1 parent f9f2776 commit 7d5fb79

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

src/tab.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,20 +2924,44 @@ impl Tab {
29242924
commands.push(Command::AutoScroll(auto_scroll));
29252925
}
29262926
Message::ClickRelease(click_i_opt) => {
2927-
if click_i_opt == self.clicked.take() {
2928-
return commands;
2927+
// Single click to open.
2928+
if !mod_ctrl && self.config.single_click {
2929+
let mut paths_to_open = Vec::new();
2930+
if let Some(ref mut items) = self.items_opt {
2931+
for (i, item) in items.iter_mut().enumerate() {
2932+
if Some(i) == click_i_opt {
2933+
if let Some(location) = &item.location_opt {
2934+
if item.metadata.is_dir() {
2935+
cd = Some(location.clone());
2936+
} else if let Some(path) = location.path_opt() {
2937+
paths_to_open.push(path.to_path_buf());
2938+
} else {
2939+
log::warn!("no path for item {:?}", item);
2940+
}
2941+
} else {
2942+
log::warn!("no location for item {:?}", item);
2943+
}
2944+
}
2945+
}
2946+
}
2947+
if !paths_to_open.is_empty() {
2948+
commands.push(Command::OpenFile(paths_to_open));
2949+
}
29292950
}
2930-
self.context_menu = None;
2931-
self.location_context_menu_index = None;
2932-
if let Some(ref mut items) = self.items_opt {
2933-
for (i, item) in items.iter_mut().enumerate() {
2934-
if mod_ctrl {
2935-
if Some(i) == click_i_opt && item.selected {
2951+
2952+
if click_i_opt != self.clicked.take() {
2953+
self.context_menu = None;
2954+
self.location_context_menu_index = None;
2955+
if let Some(ref mut items) = self.items_opt {
2956+
for (i, item) in items.iter_mut().enumerate() {
2957+
if mod_ctrl {
2958+
if Some(i) == click_i_opt && item.selected {
2959+
item.selected = false;
2960+
self.select_range = None;
2961+
}
2962+
} else if Some(i) != click_i_opt {
29362963
item.selected = false;
2937-
self.select_range = None;
29382964
}
2939-
} else if Some(i) != click_i_opt {
2940-
item.selected = false;
29412965
}
29422966
}
29432967
}
@@ -3062,24 +3086,8 @@ impl Tab {
30623086
.any(|(e_i, e)| Some(e_i) == click_i_opt.as_ref() && e.selected)
30633087
});
30643088
if let Some(ref mut items) = self.items_opt {
3065-
let mut paths_to_open = vec![];
30663089
for (i, item) in items.iter_mut().enumerate() {
30673090
if Some(i) == click_i_opt {
3068-
// Single click to open.
3069-
if !mod_ctrl && self.config.single_click {
3070-
if let Some(location) = &item.location_opt {
3071-
if item.metadata.is_dir() {
3072-
cd = Some(location.clone());
3073-
} else if let Some(path) = location.path_opt() {
3074-
paths_to_open.push(path.to_path_buf());
3075-
} else {
3076-
log::warn!("no path for item {:?}", item);
3077-
}
3078-
} else {
3079-
log::warn!("no location for item {:?}", item);
3080-
}
3081-
}
3082-
30833091
// Filter out selection if it does not match dialog kind
30843092
if let Mode::Dialog(dialog) = &self.mode {
30853093
let item_is_dir = item.metadata.is_dir();
@@ -3104,9 +3112,6 @@ impl Tab {
31043112
item.selected = false;
31053113
}
31063114
}
3107-
if !paths_to_open.is_empty() {
3108-
commands.push(Command::OpenFile(paths_to_open));
3109-
}
31103115
}
31113116
}
31123117
}

0 commit comments

Comments
 (0)