textual icon indicating copy to clipboard operation
textual copied to clipboard

AttributeError: 'Screen' object has no attribute '_select_start' (missing private API attribute)

Open windcat2333 opened this issue 6 months ago • 3 comments

Bug Description

When accessing screen._select_start in a monkey-patched auto-scroll handler, an AttributeError is raised because the _select_start attribute no longer exists on the Screen class in recent Textual versions.

AttributeError: 'Screen' object has no attribute '_select_start'

Environment

  • OS: Linux-5.15.0-173-generic-x86_64-with-glibc2.35
  • Python: 3.10.12 (main, Mar 3 2026, 11:56:32) [GCC 11.4.0]
  • Textual: 8.2.6
  • Arch: x86_64

Analysis

The code accessing screen._select_start was:

if screen._select_start is not None:
    sw = screen._select_start[0]  # expected tuple[Widget, Offset]

In Textual 8.2.6, Screen class no longer has a _select_start attribute. The old _select_start appears to have been a tuple[Widget, Offset] (widget + offset pair).

Searching the whole Textual 8.2.6 codebase shows ZERO occurrences of _select_start — it has been fully removed.

Current Screen selection API (Textual 8.2.6)

The Screen class now uses:

  • _select_state: Reactive[SelectState | None] — a SelectState(NamedTuple) containing:
    • start: SelectStart — with fields: container: Widget, container_pointer_delta: Offset, container_initial_offset: Offset, container_initial_scroll_offset: Offset, content_widget: Widget | None, content_offset: Offset | None
    • end: SelectEnd | None
  • selections: var[dict[Widget, Selection]] — map of widgets and selected ranges
  • _selecting: var(False) — boolean indicating selection in progress
  • _auto_select_scroll_timer: Timer | None — timer for auto-scroll during selection
  • _auto_select_scroll(self, direction, speed) — method that handles auto-scroll
  • _update_select(self) — method to update selection for screen-space offset

Suggested Fix

Replace the old _select_start attribute access with the new _select_state API:

# Old code (raises AttributeError):
if screen._select_start is not None:
    sw = screen._select_start[0]

# New code (compatible with current API):
if screen._select_state is not None:
    sw = screen._select_state.start.content_widget or screen._select_state.start.container
else:
    sw = widget  # fallback

Additional Notes

  • _select_start was a private API that was removed during the text selection refactor.
  • The current private API uses _select_state (of type SelectState | None) instead.
  • Public APIs like screen\.selections, screen\.get_selected_text(), and action_copy_text() remain available and unchanged.

windcat2333 avatar May 14 '26 08:05 windcat2333

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others).

This is an automated reply, generated by FAQtory

github-actions[bot] avatar May 14 '26 08:05 github-actions[bot]

I hope I solved your issue!

Consider sponsoring my work to continue to maintain and develop Textual.

  • Will McGugan

github-actions[bot] avatar May 14 '26 08:05 github-actions[bot]

Did your clanker monkey patch a private variable?

willmcgugan avatar May 14 '26 08:05 willmcgugan