summaryrefslogtreecommitdiffstats
path: root/src/syntactic/syntactic_view.rs
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-02-01 14:59:26 +0100
committerCanop <cano.petrole@gmail.com>2021-02-01 14:59:26 +0100
commit7f2246ac48845c12fe14b74e004da7e6d1999c38 (patch)
tree95ce75aece8da7a8bfda877d796801dfd5bfa684 /src/syntactic/syntactic_view.rs
parent46cfd1db5339613d2edf0207c4a0fc77dff01c0c (diff)
fix crash on page-down when last line of text preview is selected
Fix #339
Diffstat (limited to 'src/syntactic/syntactic_view.rs')
-rw-r--r--src/syntactic/syntactic_view.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/syntactic/syntactic_view.rs b/src/syntactic/syntactic_view.rs
index 60fb81b..f9c6b27 100644
--- a/src/syntactic/syntactic_view.rs
+++ b/src/syntactic/syntactic_view.rs
@@ -278,7 +278,13 @@ impl SyntacticView {
self.scroll = cmd.apply(self.scroll, self.lines.len(), self.page_height);
if let Some(idx) = self.selection_idx {
if self.scroll != old_scroll && idx >= old_scroll && idx < old_scroll + self.page_height {
- self.selection_idx = Some(idx + self.scroll - old_scroll);
+ if idx + self.scroll < old_scroll {
+ self.selection_idx = Some(0);
+ } else if idx + self.scroll - old_scroll >= self.lines.len() {
+ self.selection_idx = Some(self.lines.len() - 1);
+ } else {
+ self.selection_idx = Some(idx + self.scroll - old_scroll);
+ }
}
}
self.scroll != old_scroll