Skip to content

cmdio: make Alt+non-letter keys inert and route paste as text - #7741

Open
pietern wants to merge 2 commits into
pietern/charm-v2/03b-teainputfrom
pietern/charm-v2/03c-key-changes
Open

pietern wants to merge 2 commits into
pietern/charm-v2/03b-teainputfrom
pietern/charm-v2/03c-key-changes

Conversation

@pietern

@pietern pietern commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

These are the deliberate v1 behaviour changes, each with its golden rows:

  • Alt with a key that isn't a letter is inert. Alt+Enter, Alt+arrows, Alt+Ctrl+C and Alt+Space match no key and do nothing in prompts, selection lists and the pager. v1 acted as the plain key, because it ignored Alt on those keys. Goldens: TestKeysPin_PromptAltEnter (typed abc, not submitted), TestKeysPin_PromptAltLeft (abcX), TestKeysPin_SelectAltEnter (the list stays on screen and a later Enter picks id-02).
  • Selection lists: paste is text. A paste is literal search text when search is open and is ignored otherwise. v1 treated a paste like typed keys: a pasted j moved the cursor and a pasted / opened search. Unit test: TestSelectPaste.
  • Table view search takes the typed text, not the key's string. v1 appended alt+f for Alt+F and [text] for a paste. Golden: TestTableviewPin_SearchInput (search reads item-1; status reads match 1/10).
  • Table view search: Backspace deletes a whole character. v1 removed one byte, so after é it left a broken character behind. Now that paste feeds the search box, multi-byte input is more likely. Unit test: TestSearchBackspaceRemovesWholeRune. Select already did this.

Changelog: .nextchanges/cli/alt-keys-inert.md and paste-as-text.md.

Why

Alt+Enter submitting a prompt and Alt+Left moving the cursor were v1 side effects of ignoring Alt, not designed behaviour. No standard gives those keys a meaning, and on macOS Option sends Meta only with "Option as Meta". Making them inert also keeps the v2 key names unambiguous for the v2 swap.

Tests

  • go build ./..., golangci-lint (0 issues), gofmt clean.
  • TERM=xterm-256color go test -race -count=3 ./libs/cmdio/... ./libs/tableview/... passes.
  • Golden changes (seven files):
    • TestKeysPin_PromptAltEnter/{01-after-alt-enter,02-result}: Value: ab becomes ✔ Value: abc█.
    • TestKeysPin_PromptAltLeft/{01-after-alt-left,02-result}: abXc becomes abcX.
    • TestKeysPin_SelectAltEnter/01-after-alt-enter: the list stays on screen.
    • TestTableviewPin_SearchInput/{02-search-input,03-after-search.styled}: / italt+f[em-1]█ becomes / item-1█; no matches becomes match 1/10.
  • The pins pass otherwise without -update.
  • Full acceptance suite (go test ./acceptance/...) passes.

Stack: based on pietern/charm-v2/03b-teainput.

Manual checks for real terminals:

  • databricks selftest tui prompt, type ab, Alt+Enter, c, Enter: Entered: abc (v1: Entered: ab).
  • databricks selftest tui select --n 3, Alt+Enter: nothing happens; Enter selects the highlighted item.
  • databricks selftest tui table --rows 50: /, Alt+F, then type: the search text has no alt+f.
  • Same table: /, type é, Backspace: the search box is empty (v1: a broken character).

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: c254801

Run: 44344044741

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 19 19:42
💚​ aws-windows-latest-4core-16gb 1 274 17 11:12
💚​ azure linux-2core-8gb 1 271 19 16:29
💚​ azure-windows-latest-4core-16gb 1 273 17 12:24
💚​ gcp linux-2core-8gb 1 272 19 18:10
💚​ gcp-windows-latest-4core-16gb 1 274 17 9:54
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 41 slowest tests (at least 2 minutes):
duration env testname
5:25 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsStat
5:22 aws-windows-latest-4core-16gb TestExportDir
5:16 gcp linux-2core-8gb TestFilerRecursiveDelete/workspace_files_extensions
5:06 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
4:49 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
4:21 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsStat
4:17 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
4:07 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
4:00 aws linux-2core-8gb TestExportDir
3:39 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
3:35 aws-windows-latest-4core-16gb TestAccept
3:32 aws linux-2core-8gb TestImportDirDoesNotOverwrite
3:31 azure linux-2core-8gb TestSyncIncrementalFileSync
3:27 gcp-windows-latest-4core-16gb TestAccept
3:25 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsStat
3:22 azure-windows-latest-4core-16gb TestAccept
3:22 aws-windows-latest-4core-16gb TestSyncIncrementalFileSync
3:13 aws linux-2core-8gb TestFilerRecursiveDelete/workspace_files
3:12 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
3:11 aws-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files_extensions
3:09 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsRead
3:06 azure-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files
3:01 azure-windows-latest-4core-16gb TestFilerReadWrite/workspace_files
2:47 gcp-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
2:39 gcp-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsRead
2:35 gcp-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
2:33 azure linux-2core-8gb TestImportDirWithOverwriteFlag
2:28 gcp linux-2core-8gb TestSyncFullFileSync
2:24 gcp linux-2core-8gb TestImportDirWithOverwriteFlag
2:23 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
2:22 gcp-windows-latest-4core-16gb TestSyncFullFileSync
2:19 azure-windows-latest-4core-16gb TestFilerWorkspaceNotebook/pyNb.py
2:17 aws linux-2core-8gb TestSyncIncrementalFileOverwritesFolder
2:13 gcp linux-2core-8gb TestFilerRecursiveDelete/workspace_files
2:12 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsDelete
2:11 aws-windows-latest-4core-16gb TestFilerReadWrite/workspace_files
2:09 gcp linux-2core-8gb TestLock
2:07 azure linux-2core-8gb TestExportDir
2:05 azure linux-2core-8gb TestFilerRecursiveDelete/workspace_files
2:05 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsRead
2:03 azure-windows-latest-4core-16gb TestFilerReadDir/workspace_files

@pietern
pietern added this pull request to stack #7754 November 18, 2026 08:35
@pietern

pietern commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/review

}

case tea.KeyMsg:
if in, ok := teainput.Decode(msg); ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The select model (line 256) and pager (line 186) both guard against paste before dispatching, but the table view doesn't. In normal mode a paste event has in.Key == "", so the updateNormal switch falls through and m.viewport.Update(msg) receives the raw tea.KeyMsg. If the viewport has a key binding that matches the pasted text (e.g. a single pasted "d" hitting HalfPageDown), it would scroll. Can we add a paste guard here like the other two models?

@pietern
pietern force-pushed the pietern/charm-v2/03c-key-changes branch from 78b2bf2 to 94fea4a Compare November 18, 2026 13:07
@pietern
pietern force-pushed the pietern/charm-v2/03c-key-changes branch from 94fea4a to 558222b Compare November 18, 2026 15:55
@pietern
pietern force-pushed the pietern/charm-v2/03c-key-changes branch from 558222b to c254801 Compare November 18, 2026 16:08
@pietern

pietern commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/review

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at c254801. Each finding was verified against the code.

Not ready yet: part of the automated review did not complete.

This PR makes Alt+non-letter keys inert across prompts, selection lists, the pager and the table view, and routes paste as literal text rather than as individual key presses. The decoder change (teainput.go) and consumer updates are consistent with each other. Two minor gaps remain in the tableview: paste in normal mode isn't intercepted (unlike the select model), and backspace in search still truncates a byte rather than a rune.

Comments outside the changed lines

  • [nice to have] libs/tableview/tableview.go:338: The select model uses utf8.DecodeLastRuneInString for backspace (select.go:298), but updateSearch truncates one byte. Now that line 343 feeds in.Text (including paste) into searchInput, a multi-byte character like é followed by backspace leaves an invalid UTF-8 fragment. Consider matching the select model's pattern:
if _, size := utf8.DecodeLastRuneInString(m.searchInput); size > 0 {
    m.searchInput = m.searchInput[:len(m.searchInput)-size]
}

return m.updateSearch(in)
}
return m.updateNormal(msg)
return m.updateNormal(msg, in.Key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] A paste in normal mode has in.Key == "", so updateNormal matches no case and the raw tea.KeyMsg (with Paste: true) is forwarded to m.viewport.Update(msg) at line 290. The select model intercepts paste before the key switch (select.go:256–262); the same guard here would keep the two models consistent and avoid leaking a decoded event back into an undecoded path. Something like:

if in, ok := teainput.Decode(msg); ok {
    if in.Paste {
        if m.searching && in.Text != "" {
            m.searchInput += in.Text
        }
        return m, nil
    }
    ...
}

@pietern
pietern force-pushed the pietern/charm-v2/03c-key-changes branch from c254801 to 21cecc5 Compare November 20, 2026 13:23
@pietern
pietern force-pushed the pietern/charm-v2/03c-key-changes branch from 21cecc5 to 816536e Compare November 20, 2026 22:30
pietern and others added 2 commits November 23, 2026 15:45
…paste as text

These are the deliberate v1 behaviour changes, each with its golden rows:

- Alt stays in the key name for every non-rune key, so Alt+Enter,
  Alt+arrows, Alt+Ctrl+C and Alt+Space match no case and do nothing in
  prompts, selection lists and the pager. v1 acted as the plain key,
  because it ignored Alt on those keys. Goldens: TestKeysPin_PromptAltEnter,
  TestKeysPin_PromptAltLeft, TestKeysPin_SelectAltEnter.
- A paste in a selection list is literal search text when search is open
  and is ignored otherwise. v1 treated a paste like typed keys, so a pasted
  "j" moved the cursor and a pasted "/" opened search. Pinned by
  TestSelectPaste.
- The table view's search takes Text, not msg.String(). v1 appended
  "alt+f" for Alt+F and "[text]" for a paste. Goldens:
  TestTableviewPin_SearchInput (search input and status line now read
  "match 1/10").

Changelog: .nextchanges/cli/alt-keys-inert.md.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@pietern
pietern force-pushed the pietern/charm-v2/03c-key-changes branch from 816536e to eb4baca Compare November 23, 2026 15:47
@pietern
pietern marked this pull request as ready for review November 23, 2026 15:49
@pietern
pietern requested review from a team as code owners November 23, 2026 15:49
@pietern

pietern commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/review

@pietern
pietern requested a review from rauchy November 23, 2026 15:49

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at eb4baca. Each finding was verified against the code.

No blocking issues found. 3 non-blocking comment(s) and 1 question(s) below.

This PR keeps the alt+ prefix on every key in teainput.Decode, so Alt+Enter, Alt+arrows and Alt+Space now do nothing. It also routes bracketed paste as text in select and table view search, and makes table view Backspace delete a whole rune. The goldens and new unit tests cover the intended changes. Three things are left: Esc can now arrive as alt+esc and stop quitting, pasted line breaks go straight into the table view search, and the old Backspace/Tab branch in Decode no longer does anything.

Questions

  1. The rune-safe Backspace fix in table view search (TestSearchBackspaceRemovesWholeRune) also fixes a bug you can already hit on the base branch by typing é, separately from the Alt/paste change. Should it go in its own PR, as AGENTS.md's one-change-per-PR rule asks, or is it tied closely enough to paste-as-text to stay here? (non-blocking)

Comment thread libs/cmdio/pager.go
@@ -198,7 +198,7 @@ func (m *pagerModel[T]) handleKey(key string) (tea.Model, tea.Cmd) {
return m, m.startDrain()
case "esc", "ctrl+c", "q", "Q":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] Decode used to drop alt+ here, so an Esc that reached Bubble Tea v1 with Alt set still matched esc. As far as I can tell, two quick Esc presses, or an Esc in the same read as the next byte, decode as Alt+Esc. That input is now alt+esc and matches nothing, so the pager doesn't quit. The same applies to the esc cases in tableview updateNormal/updateSearch. Was Alt+Esc meant to be inert too? If not, could Decode keep dropping Alt for Esc, or could these switches also match alt+esc?

m.searchInput += msg.String()
}
// Only accept printable characters (typed or pasted).
m.searchInput += in.Text

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] A paste now reaches this line as in.Text unfiltered, so the comment "Only accept printable characters" is wrong for pastes. Pasting item-1 copied with its trailing newline puts item-1\n in the search box. The footer then wraps onto a line searchFooterHeight didn't reserve, and Enter shows no matches because findMatches searches lines already split on \n. Should pasted text be cut at the first line break, or have its \r/\n stripped, before it's appended?

}
return printable(" "), true
case tea.KeyBackspace, tea.KeyCtrlH, tea.KeyTab:
case tea.KeyBackspace, tea.KeyTab:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Now that the fall-through returns Event{Key: k.String()}, the case tea.KeyBackspace, tea.KeyTab: if k.Alt { ... } branch returns exactly what the fall-through would. Can it be dropped, along with "backspace and tab" in the //nolint:exhaustive reason on line 44?

This branch has not been deployed

No deployments
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