diff options
author | DLFW <daniel@llin.info> | 2021-06-21 02:40:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-20 20:40:44 -0400 |
commit | 68a6bf78cfe6d0a46f15f2e80e917ffb69b8c963 (patch) | |
tree | d293189829d59dd5d8e8b8265d494a03f5975737 /src/util | |
parent | e6359a599e804031189eb9bc067c4eff9b01a1a8 (diff) |
Fix selecting an entry by mouse click when show_borders=true (#77)
* encapsulate paging strategy
This commit introduces one central place where the “paging” (first entry
of a dir list shown in the UI) strategy is implemented.
This decreases the risk for copy-paste mistakes, makes it easier to
change it, and would make the implementation of a configurable paging
strategy easier.
* fix: correct new index on click for parent column
And a little refactoring of the code that handles the left click.
* fix: consider borders on left click
When selecting a dir entry with a left click of the mouse, the borders
were not considered, which led to
1. a faulty, constant y offset of 1 row
2. a faulty offset, which increased with each page scrolled down, due to
a wrong calculation of the content height
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/input.rs | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/util/input.rs b/src/util/input.rs index 1d4b469..7a6d9ad 100644 --- a/src/util/input.rs +++ b/src/util/input.rs @@ -16,7 +16,13 @@ pub fn process_mouse(event: MouseEvent, context: &mut AppContext, backend: &mut let constraints: &[Constraint; 3] = &context.config_ref().display_options_ref().default_layout; let layout_rect = Layout::default() .direction(Direction::Horizontal) - .vertical_margin(1) + .vertical_margin( + if context.config_ref().display_options_ref().show_borders() { + 2 + } else { + 1 + }, + ) .constraints(constraints.as_ref()) .split(f_size); @@ -54,28 +60,28 @@ pub fn process_mouse(event: MouseEvent, context: &mut AppContext, backend: &mut 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[1].x { - if let Some(dirlist) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { - if let Some(curr_index) = dirlist.index { - let skip_dist = curr_index / layout_rect[1].height as usize - * layout_rect[1].height as usize; - - let new_index = skip_dist + (y - layout_rect[1].y - 1) as usize; - if let Err(e) = parent_cursor_move::parent_cursor_move(new_index, context) { - context.push_msg(e.to_string()); - } - } - } - } else if x < layout_rect[2].x { - if let Some(dirlist) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { - if let Some(curr_index) = dirlist.index { - let skip_dist = curr_index / layout_rect[1].height as usize - * layout_rect[1].height as usize; - - let new_index = skip_dist + (y - layout_rect[1].y - 1) as usize; - if let Err(e) = cursor_move::cursor_move(new_index, context) { - context.push_msg(e.to_string()); - } + if x < layout_rect[2].x { + let (dirlist, is_parent) = if x < layout_rect[1].x { + ( + context.tab_context_ref().curr_tab_ref().parent_list_ref(), + true, + ) + } else { + ( + context.tab_context_ref().curr_tab_ref().curr_list_ref(), + false, + ) + }; + if let Some(dirlist) = dirlist { + let skip_dist = + dirlist.first_index_for_viewport(layout_rect[1].height as usize); + let new_index = skip_dist + (y - layout_rect[1].y - 1) as usize; + if let Err(e) = if is_parent { + parent_cursor_move::parent_cursor_move(new_index, context) + } else { + cursor_move::cursor_move(new_index, context) + } { + context.push_msg(e.to_string()); } } } else { |