From a8b0980897ecd99ef6d0fe2efd2b5f0e28058d06 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Sun, 13 Apr 2025 03:26:10 +0200 Subject: [PATCH] Fix selection highlight at the end of the document --- src/buffer.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/buffer.rs b/src/buffer.rs index 128954e..f4b0966 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1634,7 +1634,12 @@ impl TextBuffer { ); // Draw the selection on this line, if any. - if selection_beg <= cursor_end.logical_pos && selection_end >= cursor_beg.logical_pos { + // FYI: `cursor_beg.visual_pos.y == visual_line` is necessary as the `visual_line` + // may be past the end of the document, and so it may not receive a highlight. + if cursor_beg.visual_pos.y == visual_line + && selection_beg <= cursor_end.logical_pos + && selection_end >= cursor_beg.logical_pos + { // By default, we assume the entire line is selected. let mut beg = 0; let mut end = COORD_TYPE_SAFE_MAX;