Skip to content

refactor(tui): extract _select_origin_widget helper + add unit tests#376

Open
EthanGuo-coder wants to merge 1 commit into
lsdefine:mainfrom
EthanGuo-coder:fix/issue-373
Open

refactor(tui): extract _select_origin_widget helper + add unit tests#376
EthanGuo-coder wants to merge 1 commit into
lsdefine:mainfrom
EthanGuo-coder:fix/issue-373

Conversation

@EthanGuo-coder
Copy link
Copy Markdown

@EthanGuo-coder EthanGuo-coder commented May 14, 2026

This is a follow-up refactor on top of #379, which already landed the Textual 8.x compat shim inline inside _patch_auto_scroll_for_selection.

Changes:

  • Extract the inline _select_state vs _select_start branch into a module-level helper _select_origin_widget(screen). The call site becomes a one-liner.
  • Add a defensive None-guard on _select_state.start. The current inline version assumes start is always present whenever _select_state is — that holds for the Textual 8.2.6 shape today, but the helper degrades gracefully if a future version exposes a mid-drag _select_state whose start is still None.
  • Add tests/test_tuiapp_v2_select_origin.py with 6 unit tests stubbing screen directly (no real Textual instance required) to cover:
    • Textual 8.x happy path — returns _select_state.start.container.
    • Textual 8.x with _select_state is None — returns None.
    • Textual 8.x with start is None — returns None.
    • Legacy Textual ≤7.x happy path — returns _select_start[0].
    • Legacy ≤7.x with _select_start is None — returns None.
    • Neither attribute present — returns None.

No behaviour change for users on the path #379 already covers. Rebased onto current main (fc6b5ad).

Refs #373, #379

Refactor the Textual 8.x compat candidate-resolution that lsdefine#379 just
landed in _patch_auto_scroll_for_selection. Extract the inline 8.x
vs ≤7.x branch into a module-level _select_origin_widget(screen)
helper, add a defensive None-guard on start (in case _select_state
exists but start is None mid-drag), and cover both paths with unit
tests stubbing screen — no real Textual required.

Refs lsdefine#373, lsdefine#379

Co-Authored-By: Claude <noreply@anthropic.com>
@EthanGuo-coder EthanGuo-coder changed the title fix(tui): compat tuiapp_v2 selection auto-scroll with Textual 8.x refactor(tui): extract _select_origin_widget helper + add unit tests May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant