on main help sign in
Merge pull request #637 from charmbracelet/charm-540-fix-selection-panic

fix(selection): fix panic that can happen on selection

commita9e52216044f21dd1955ec4ad9af6e6781ff4232 authorKujtim Hoxha <kujtimii.h@gmail.com> dateFri 8 Aug 2025, 00:04 (1 year ago) parentbae88d6fd890f1
1 file changed+8−4
internal/tui/exp/list/list.go+8−4
internal/tui/exp/list/list.go+8−4
@@ -1306,6 +1306,10 @@ func (l *list[T]) findWordBoundaries(col, line int) (startCol, endCol int) {
13061306 }
13071307 }
13081308
1309+ if line < 0 || line >= len(lines) {
1310+ return 0, 0
1311+ }
1312+
13091313 currentLine := lines[line]
13101314 gr := uniseg.NewGraphemes(currentLine)
13111315 startCol = -1
@@ -1340,10 +1344,6 @@ func (l *list[T]) findParagraphBoundaries(line int) (startLine, endLine int, fou
13401344 line = (len(lines) - 1) - l.height + line + 1
13411345 }
13421346
1343− if strings.TrimSpace(lines[line]) == "" {
1344− return 0, 0, false
1345− }
1346−
13471347 if l.offset > 0 {
13481348 if l.direction == DirectionBackward {
13491349 line -= l.offset
@@ -1357,6 +1357,10 @@ func (l *list[T]) findParagraphBoundaries(line int) (startLine, endLine int, fou
13571357 return 0, 0, false
13581358 }
13591359
1360+ if strings.TrimSpace(lines[line]) == "" {
1361+ return 0, 0, false
1362+ }
1363+
13601364 // Find start of paragraph (search backwards for empty line or start of text)
13611365 startLine = line
13621366 for startLine > 0 && strings.TrimSpace(lines[startLine-1]) != "" {