From fd890f19c893325eb80aa0d6f0edade3f40b6b47 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 7 Aug 2025 17:12:36 -0300 Subject: [PATCH] fix(selection): fix panic that can happen on selection --- internal/tui/exp/list/list.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/tui/exp/list/list.go b/internal/tui/exp/list/list.go index 595e21334d37b218f3d4fc8892cd03e4a1010d41..8cc5461b5e21e25f2a3faf00510cdd90ea353a38 100644 --- a/internal/tui/exp/list/list.go +++ b/internal/tui/exp/list/list.go @@ -1306,6 +1306,10 @@ func (l *list[T]) findWordBoundaries(col, line int) (startCol, endCol int) { } } + if line < 0 || line >= len(lines) { + return 0, 0 + } + currentLine := lines[line] gr := uniseg.NewGraphemes(currentLine) startCol = -1 @@ -1340,10 +1344,6 @@ func (l *list[T]) findParagraphBoundaries(line int) (startLine, endLine int, fou line = (len(lines) - 1) - l.height + line + 1 } - if strings.TrimSpace(lines[line]) == "" { - return 0, 0, false - } - if l.offset > 0 { if l.direction == DirectionBackward { line -= l.offset @@ -1357,6 +1357,10 @@ func (l *list[T]) findParagraphBoundaries(line int) (startLine, endLine int, fou return 0, 0, false } + if strings.TrimSpace(lines[line]) == "" { + return 0, 0, false + } + // Find start of paragraph (search backwards for empty line or start of text) startLine = line for startLine > 0 && strings.TrimSpace(lines[startLine-1]) != "" {