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]) != "" {