Skip to content

Selection.extract() crashes with IndexError #6428

@karanjaxyz

Description

@karanjaxyz

Have you checked closed issues? Yes
Have you checked against the most recent version of Textual? Yes

The bug

Selection.extract() crashes with IndexError: list index out of range when selecting text in a single-line widget positioned below row 0 on screen.
Widget.get_selection() passes the selection's coordinates directly to Selection.extract() without translating them to widget-local text coordinates. extract() bounds-checks end_line but not start_line, causing the crash when start_line exceeds the text line count.

To reproduce the bug:

from textual.selection import Selection
from textual.geometry import Offset

sel = Selection(start=Offset(x=140, y=13), end=None)
sel.extract("▶ Loaded: 40 skills")  # IndexError thrown: list index out of range
textual diagnose

Textual Diagnostics

Versions

Name Value
Textual 8.1.1
Rich 14.3.3

Python

Name Value
Version 3.10.9
Implementation CPython
Compiler Clang 13.0.0 (clang-1300.0.29.30)
Executable /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10

Operating System

Name Value
System Darwin
Release 22.6.0
Version Darwin Kernel Version 22.6.0: Tue Jul 15 08:22:28 PDT 2025; root:xnu-8796.141.3.713.2~2/RELEASE_X86_64

Terminal

Name Value
Terminal Application vscode (1.110.0)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=108, height=14
legacy_windows False
min_width 1
max_width 108
is_terminal True
encoding utf-8
max_height 14
justify None
overflow None
no_wrap False
highlight None
markup None
height None

Discovered via this issuue: OpenHands CLI #13408

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions