Flatten deep nesting in _multiselect_loop #292

Open
didericis-claude wants to merge 1 commits from flatten-deep-nesting into main
Collaborator

Closes #288.

Summary

_multiselect_loop in bot_bottle/cli/tui.py nested key dispatch up to six indent levels — the space-bar toggle (whileif focus == "filter"elif key == SPACEif filteredif/else membership) and the long order-mode elif chain wrapped inside the focus branch.

Two behaviour-identical helpers pull it back under four levels:

  • _toggle_membership(items, item) — collapses the add/remove if/else, flattening the space branch.
  • _handle_order_key(key, selected, order_cursor) — moves the whole order-focus dispatch out of the loop and returns the new cursor.

No key bindings or control flow change; the loop's early returns and focus toggling are untouched. The extracted helpers are covered by a behavioural sanity check (toggle, reorder up/down, remove, navigate) and the full unit suite (1297 tests) passes; pyright clean.

Note on git_gate.py

The deep-looking lines in git_gate.py named in the issue are multiline call-argument continuations, already under four levels of actual control nesting, so no change was warranted there. The flattening is focused where it mattered.

Closes #288. ## Summary `_multiselect_loop` in `bot_bottle/cli/tui.py` nested key dispatch up to six indent levels — the space-bar toggle (`while` → `if focus == "filter"` → `elif key == SPACE` → `if filtered` → `if/else` membership) and the long order-mode `elif` chain wrapped inside the focus branch. Two behaviour-identical helpers pull it back under four levels: - `_toggle_membership(items, item)` — collapses the add/remove `if/else`, flattening the space branch. - `_handle_order_key(key, selected, order_cursor)` — moves the whole order-focus dispatch out of the loop and returns the new cursor. No key bindings or control flow change; the loop's early returns and focus toggling are untouched. The extracted helpers are covered by a behavioural sanity check (toggle, reorder up/down, remove, navigate) and the full unit suite (1297 tests) passes; pyright clean. ## Note on git_gate.py The deep-looking lines in `git_gate.py` named in the issue are multiline call-argument continuations, already under four levels of actual control nesting, so no change was warranted there. The flattening is focused where it mattered.
didericis-claude added 1 commit 2026-06-25 19:39:01 -04:00
refactor(tui): flatten _multiselect_loop key handling
lint / lint (push) Successful in 1m49s
test / unit (pull_request) Successful in 43s
test / integration (pull_request) Successful in 19s
4ab48a77ff
The interactive multiselect loop nested key dispatch up to six indent
levels deep — the worst offender being the space-bar toggle
(while > if focus > elif key > if filtered > if/else membership) and
the long order-mode elif chain inside the focus branch.

Extract two behaviour-identical helpers:
- `_toggle_membership(items, item)` collapses the add/remove if/else,
  pulling the space branch back to four levels.
- `_handle_order_key(key, selected, order_cursor)` moves the entire
  order-focus dispatch out of the loop, returning the new cursor.

No control-flow or key-binding changes; the loop's early returns and
focus toggling are untouched. (git_gate.py's deep-looking lines named
in the issue are multiline call-argument continuations already under
four levels of control nesting, so no change was warranted there.)

Closes #288

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NkwFXLFff9PYPy4wgVBJp9
Some checks are pending
lint / lint (push) Successful in 1m49s
test / unit (pull_request) Successful in 43s
test / integration (pull_request) Successful in 19s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin flatten-deep-nesting:flatten-deep-nesting
git checkout flatten-deep-nesting
Sign in to join this conversation.