summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/misc.md23
-rw-r--r--src/event/process_event.rs85
2 files changed, 91 insertions, 17 deletions
diff --git a/docs/misc.md b/docs/misc.md
index 534e04b..d0911c4 100644
--- a/docs/misc.md
+++ b/docs/misc.md
@@ -41,4 +41,27 @@ This way, visual mode can be helpful to build up a selection of multiple ranges
The other option is to issue the `escape` command, by default mapped to the `ESCAPE` key.
When using `escape`, the current visual-mode-selection will be withdrawn.
+## Mouse Control
+When built with the `mouse` feature, Joshuto supports some mouse control,
+which behaves very similar to *ranger*.
+⚠ Disclaimer: Mouse control does not work properly in `hsplit` mode.
+(See [joshuto.toml docs](configuration/joshuto.toml.md#Different_view_layouts).)
+
+If you click a file or directory with the *left mouse button*,
+the cursor in the particular list will move to the clicked entry.
+If the file or directory clicked is in the parent or children panel,
+that directory level will be moved to the “current” panel in the middle.
+
+If you click a directory in the *parent panel with the right mouse button*,
+that directory will be opened, means, its content will appear in the middle panel.
+
+If you click a file or directory in the *middle panel with the right mouse button*,
+that file or directory will be opened, just like when pressing the “right arrow”.
+
+The cursor in the parent and in the middle panel can be scrolled by using the *mouse wheel*.
+
+Unlike ranger, it’s currently not possible to scroll the children-panel or a preview
+with the mouse wheel.
+
+Unlike ranger, Joshuto allows to set the cursor in the children-panel with a right click.
diff --git a/src/event/process_event.rs b/src/event/process_event.rs
index 5b759d7..4f566ea 100644
--- a/src/event/process_event.rs
+++ b/src/event/process_event.rs
@@ -226,6 +226,27 @@ pub fn process_unsupported(
}
}
+enum Panel {
+ Parent,
+ Current,
+ Preview,
+}
+
+fn children_cursor_move(context: &mut AppContext, new_index: usize) {
+ let mut new_index = new_index;
+ let ui_context = context.ui_context_ref().clone();
+ let display_options = context.config_ref().display_options_ref().clone();
+ if let Some(children_list) = context.tab_context_mut().curr_tab_mut().child_list_mut() {
+ if !children_list.is_empty() {
+ let dir_len = children_list.len();
+ if new_index >= dir_len {
+ new_index = dir_len - 1;
+ }
+ children_list.set_index(Some(new_index), &ui_context, &display_options);
+ }
+ }
+}
+
pub fn process_mouse(
event: MouseEvent,
context: &mut AppContext,
@@ -278,37 +299,67 @@ pub fn process_mouse(
// TODO: scroll in child list
}
}
- MouseEvent::Press(MouseButton::Left, x, y)
- if y > layout_rect[1].y && y <= layout_rect[1].y + layout_rect[1].height =>
- {
- if x < layout_rect[2].x {
- let (dirlist, is_parent) = if x < layout_rect[1].x {
+ MouseEvent::Press(button @ MouseButton::Left, x, y)
+ | MouseEvent::Press(button @ MouseButton::Right, x, y) => {
+ if y > layout_rect[1].y && y <= layout_rect[1].y + layout_rect[1].height {
+ let (dirlist, panel) = if x < layout_rect[1].x {
(
- context.tab_context_ref().curr_tab_ref().parent_list_ref(),
- true,
+ context.tab_context_mut().curr_tab_mut().parent_list_ref(),
+ Some(Panel::Parent),
+ )
+ } else if x < layout_rect[2].x {
+ (
+ context.tab_context_mut().curr_tab_mut().curr_list_ref(),
+ Some(Panel::Current),
)
} else {
(
- context.tab_context_ref().curr_tab_ref().curr_list_ref(),
- false,
+ context.tab_context_mut().curr_tab_mut().child_list_ref(),
+ Some(Panel::Preview),
)
};
if let Some(dirlist) = dirlist {
let skip_dist = dirlist.first_index_for_viewport();
let new_index = skip_dist + (y - layout_rect[1].y - 1) as usize;
- if is_parent {
- if let Err(e) = parent_cursor_move::parent_cursor_move(context, new_index) {
- context.message_queue_mut().push_error(e.to_string());
+ match panel {
+ Some(Panel::Parent) => {
+ if let Err(e) =
+ parent_cursor_move::parent_cursor_move(context, new_index)
+ {
+ context.message_queue_mut().push_error(e.to_string());
+ };
+ if button == MouseButton::Left {
+ let command = Command::ChangeDirectory {
+ path: path::PathBuf::from(".."),
+ };
+ if let Err(e) = command.execute(context, backend, keymap_t) {
+ context.message_queue_mut().push_error(e.to_string());
+ }
+ };
+ }
+ Some(Panel::Current) => {
+ cursor_move::cursor_move(context, new_index);
+ if button == MouseButton::Right {
+ let command = Command::OpenFile;
+ if let Err(e) = command.execute(context, backend, keymap_t) {
+ context.message_queue_mut().push_error(e.to_string());
+ }
+ }
}
- } else {
- cursor_move::cursor_move(context, new_index);
+ Some(Panel::Preview) => {
+ children_cursor_move(context, new_index);
+ if button == MouseButton::Left {
+ let command = Command::OpenFile;
+ if let Err(e) = command.execute(context, backend, keymap_t) {
+ context.message_queue_mut().push_error(e.to_string());
+ }
+ }
+ }
+ _ => {}
}
}
- } else {
}
}
- MouseEvent::Press(MouseButton::Left, _, y)
- if y > layout_rect[1].y && y <= layout_rect[1].y + layout_rect[1].height => {}
_ => {}
}
context.flush_event();