aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorMichael Davis2022-11-03 06:09:21 +0000
committerGitHub2022-11-03 06:09:21 +0000
commitba394dca6d3a5b52622c4d7b0d3aba7c30af9701 (patch)
treeb5ee33c8246d295a9ac2a74bada35d1cc37218f6 /helix-term/src
parent1bed2f30435cfa45502ad2c481a1f4ffe4a1119a (diff)
Fix panic from two windows editing the same document (#4570)
* Clamp highlighting range to be within document This fixes a panic possible when two vsplits of the same document exist and enough lines are deleted from the document so that one of the windows focuses past the end of the document. * Ensure cursor is in view on window change If two windows are editing the same document, one may delete enough of the document so that the other window is pointing at a blank page (past the document end). In this change we ensure that the cursor is within view whenever we switch to a new window (for example with `<C-w>w`). * Update helix-term/src/ui/editor.rs Co-authored-by: Blaž Hrastnik <blaz@mxxn.io> Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/ui/editor.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 72c9d15e..2cd2ad05 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -227,16 +227,16 @@ impl EditorView {
_theme: &Theme,
) -> Box<dyn Iterator<Item = HighlightEvent> + 'doc> {
let text = doc.text().slice(..);
- let last_line = std::cmp::min(
- // Saturating subs to make it inclusive zero indexing.
- (offset.row + height as usize).saturating_sub(1),
- doc.text().len_lines().saturating_sub(1),
- );
let range = {
- // calculate viewport byte ranges
- let start = text.line_to_byte(offset.row);
- let end = text.line_to_byte(last_line + 1);
+ // Calculate viewport byte ranges:
+ // Saturating subs to make it inclusive zero indexing.
+ let last_line = doc.text().len_lines().saturating_sub(1);
+ let last_visible_line = (offset.row + height as usize)
+ .saturating_sub(1)
+ .min(last_line);
+ let start = text.line_to_byte(offset.row.min(last_line));
+ let end = text.line_to_byte(last_visible_line + 1);
start..end
};