summaryrefslogtreecommitdiffstats
path: root/src/fs
diff options
context:
space:
mode:
authorDLFW <daniel@llin.info>2021-06-21 02:40:44 +0200
committerGitHub <noreply@github.com>2021-06-20 20:40:44 -0400
commit68a6bf78cfe6d0a46f15f2e80e917ffb69b8c963 (patch)
treed293189829d59dd5d8e8b8265d494a03f5975737 /src/fs
parente6359a599e804031189eb9bc067c4eff9b01a1a8 (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/fs')
-rw-r--r--src/fs/dirlist.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs
index b80e05b..e8dc90b 100644
--- a/src/fs/dirlist.rs
+++ b/src/fs/dirlist.rs
@@ -143,6 +143,17 @@ impl JoshutoDirList {
self.get_curr_mut_(self.index?)
}
+ /// For a given number of entries, visible in a UI, this method returns the index of the entry
+ /// with which the UI should start to list the entries.
+ ///
+ /// This method assures that the cursor is always in the viewport of the UI.
+ pub fn first_index_for_viewport(&self, viewport_height: usize) -> usize {
+ match self.index {
+ Some(index) => index / viewport_height as usize * viewport_height as usize,
+ None => 0,
+ }
+ }
+
fn get_curr_mut_(&mut self, index: usize) -> Option<&mut JoshutoDirEntry> {
if index < self.contents.len() {
Some(&mut self.contents[index])