Skip to content

tui: Fix Shift+Tab kline sampling reverse cycle - #314

Merged
huacnlee merged 1 commit into
longbridge:mainfrom
fengli-master:tui/fix-shift-tab-kline
Sep 1, 2026
Merged

tui: Fix Shift+Tab kline sampling reverse cycle#314
huacnlee merged 1 commit into
longbridge:mainfrom
fengli-master:tui/fix-shift-tab-kline

Conversation

@fengli-master

Copy link
Copy Markdown
Contributor

? documents TAB, Shift+TAB as switching kline sampling both ways. Tab worked; Shift+Tab did nothing, on foot and any other terminal that sends CSI Z.

There is no existing issue for this.

Cause

crossterm 0.29 parses CSI Z (\e[Z, terminfo kcbt) as KeyCode::BackTab with KeyModifiers::SHIFT:

b'Z' => Some(Event::Key(KeyEvent::new_with_kind(
    KeyCode::BackTab,
    KeyModifiers::SHIFT,
    KeyEventKind::Press,
))),

The keymap bound BackTab with KeyModifiers::NONE and compared chords exactly. BackTab+NONE never equalled BackTab+SHIFT, so ActionId::BackTab was never dispatched and KlineType::prev() never ran.

KlineType::next() also clamps at Year rather than wrapping, so Tab cannot be used as a reverse path either.

The same miss happens on xterm, kitty, alacritty, and wezterm — not only foot. Kitty's CSI-u protocol reports Shift+Tab as Tab+SHIFT, which was also unmatched.

Fix

Fold the three encodings onto one chord in KeyChord::normalized(), the same way G and Shift+g are already folded:

  • BackTab+SHIFT (crossterm 0.29 / CSI Z)
  • Tab+SHIFT (kitty keyboard protocol)
  • BackTab with no modifiers (older parsers)

Plain Tab is unchanged and still moves sampling forward.

Checks

  • cargo fmt
  • cargo clippy --bin longbridge -- -D warnings
  • cargo test --bin longbridge tui::keymap (9 tests, including the new encoding cases)

crossterm 0.29 reports CSI Z (Shift+Tab on foot, xterm, and similar
terminals) as BackTab with the SHIFT modifier. The keymap bound BackTab
with no modifiers and compared chords exactly, so Shift+Tab never
dispatched ActionId::BackTab and kline sampling could only move forward.

Fold BackTab+SHIFT, Tab+SHIFT, and bare BackTab onto one chord so the
existing binding matches every common encoding.
@huacnlee
huacnlee merged commit d7d96f6 into longbridge:main Sep 1, 2026
1 check passed
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.

2 participants