From 5e4765cef3b4fd9b4b172d2bbc409490b77e6e53 Mon Sep 17 00:00:00 2001 From: "pieter.noordhuis" Date: Tue, 17 Nov 2026 20:27:09 +0000 Subject: [PATCH 1/2] cmdio: make Alt+non-letter keys inert and route select and tableview 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 --- .nextchanges/cli/alt-keys-inert.md | 2 ++ .../01-after-alt-enter.golden | 2 +- .../02-result.golden | 2 +- .../01-after-alt-left.golden | 2 +- .../02-result.golden | 2 +- .../01-after-alt-enter.golden | 6 +++- .../02-search-input.golden | 2 +- .../03-after-search.styled.golden | 2 +- libs/cmdio/pager.go | 2 +- libs/cmdio/select.go | 9 ++++++ libs/cmdio/select_test.go | 31 +++++++++++++++++++ libs/cmdio/teainput/press_test.go | 2 +- libs/cmdio/teainput/teainput.go | 11 +++---- libs/cmdio/teainput/teainput_test.go | 7 ++--- libs/tableview/tableview.go | 26 +++++++++------- 15 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 .nextchanges/cli/alt-keys-inert.md diff --git a/.nextchanges/cli/alt-keys-inert.md b/.nextchanges/cli/alt-keys-inert.md new file mode 100644 index 00000000000..08e41aee2d3 --- /dev/null +++ b/.nextchanges/cli/alt-keys-inert.md @@ -0,0 +1,2 @@ +* Alt with a key that isn't a letter (Alt+Enter, Alt+arrows, Alt+Space) no longer acts as that key in prompts, selection lists and the pager. Alt+Enter used to submit and Alt+Left used to move the cursor. +* Selection lists treat pasted text as typed search text, and ignore it outside search. Pasting `j` or `/` no longer moves the cursor or opens search. The table view's search no longer inserts `alt+f` for Alt+F or `[text]` for a paste. diff --git a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/01-after-alt-enter.golden b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/01-after-alt-enter.golden index fb674f6cc35..02d12786660 100644 --- a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/01-after-alt-enter.golden +++ b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/01-after-alt-enter.golden @@ -1 +1 @@ -Value: ab +✔ Value: abc█ diff --git a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/02-result.golden b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/02-result.golden index 679aaf570a0..215a72e354d 100644 --- a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/02-result.golden +++ b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltEnter/02-result.golden @@ -1,2 +1,2 @@ -value: "ab" +value: "abc" err: diff --git a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/01-after-alt-left.golden b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/01-after-alt-left.golden index c8782899a3c..2ff8a689db4 100644 --- a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/01-after-alt-left.golden +++ b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/01-after-alt-left.golden @@ -1 +1 @@ -✔ Value: abX█ +✔ Value: abcX█ diff --git a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/02-result.golden b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/02-result.golden index 73479308a89..34269fe5786 100644 --- a/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/02-result.golden +++ b/libs/cmdio/cmdiotest/testdata/TestKeysPin_PromptAltLeft/02-result.golden @@ -1,2 +1,2 @@ -value: "abXc" +value: "abcX" err: diff --git a/libs/cmdio/cmdiotest/testdata/TestKeysPin_SelectAltEnter/01-after-alt-enter.golden b/libs/cmdio/cmdiotest/testdata/TestKeysPin_SelectAltEnter/01-after-alt-enter.golden index 8b137891791..b5462b0e045 100644 --- a/libs/cmdio/cmdiotest/testdata/TestKeysPin_SelectAltEnter/01-after-alt-enter.golden +++ b/libs/cmdio/cmdiotest/testdata/TestKeysPin_SelectAltEnter/01-after-alt-enter.golden @@ -1 +1,5 @@ - +Search: █ +? Pick one: + alpha + beta (id-02) + gamma diff --git a/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/02-search-input.golden b/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/02-search-input.golden index 4e5c432cf9a..2f795671d21 100644 --- a/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/02-search-input.golden +++ b/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/02-search-input.golden @@ -37,4 +37,4 @@ item-20 ready 20 rows -/ italt+f[em-1]█ +/ item-1█ diff --git a/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/03-after-search.styled.golden b/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/03-after-search.styled.golden index 2ca2de8e891..bf068579698 100644 --- a/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/03-after-search.styled.golden +++ b/libs/cmdio/cmdiotest/testdata/TestTableviewPin_SearchInput/03-after-search.styled.golden @@ -37,4 +37,4 @@ item-20 ready -20 rows | no matches | ←→↑↓ scroll | g/G top/bottom | / search | q quit | 100% +20 rows | match 1/10 | n/N next/prev | ←→↑↓ scroll | g/G top/bottom | / search | q quit | 100% diff --git a/libs/cmdio/pager.go b/libs/cmdio/pager.go index 7462c12adc6..4f6c48b91f2 100644 --- a/libs/cmdio/pager.go +++ b/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": return m, tea.Quit - case "space", "alt+space": // Alt+Space has always advanced the pager. + case "space": return m, m.startAdvance() } return m, nil diff --git a/libs/cmdio/select.go b/libs/cmdio/select.go index a575a7eeb04..47dd423b393 100644 --- a/libs/cmdio/select.go +++ b/libs/cmdio/select.go @@ -253,6 +253,15 @@ func (m *selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if !ok { return m, nil } + if in.Paste { + // A paste is literal filter text: it doesn't navigate or toggle + // search the way typed "j", "k" or "/" do. + if m.searchActive && in.Text != "" { + m.appendFilter(in.Text) + } + return m, nil + } + switch in.Key { case "ctrl+c": m.cancelled = true diff --git a/libs/cmdio/select_test.go b/libs/cmdio/select_test.go index de19d2dbcae..61e9477cf08 100644 --- a/libs/cmdio/select_test.go +++ b/libs/cmdio/select_test.go @@ -1,8 +1,10 @@ package cmdio import ( + "strings" "testing" + "github.com/databricks/cli/libs/cmdio/teainput" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -39,3 +41,32 @@ func TestRunSelectNoColor(t *testing.T) { assert.Contains(t, out, ansiBold) assert.Contains(t, out, ansiUnderline) } + +// A paste is text, not keys: outside search it neither moves the cursor nor +// opens search, and inside search it is appended literally, "/" included. +func TestSelectPaste(t *testing.T) { + opts := SelectOptions{ + Label: "Pick", + Items: []Tuple{{"alpha", "1"}, {"beta", "2"}, {"gamma", "3"}}, + Searcher: func(input string, idx int) bool { + return strings.Contains(strings.ToLower(input), "a") + }, + } + m, err := newSelectModel(opts, false) + require.NoError(t, err) + + next, _ := m.Update(teainput.Paste("j/")) + m = next.(*selectModel) + assert.Equal(t, 0, m.cursor, "a pasted j must not move the cursor") + assert.False(t, m.searchActive, "a pasted / must not open search") + assert.Empty(t, m.filter) + + next, _ = m.Update(teainput.Press("/")) + m = next.(*selectModel) + require.True(t, m.searchActive) + + next, _ = m.Update(teainput.Paste("b/x")) + m = next.(*selectModel) + assert.True(t, m.searchActive, "a pasted / inside search is literal") + assert.Equal(t, "b/x", m.filter) +} diff --git a/libs/cmdio/teainput/press_test.go b/libs/cmdio/teainput/press_test.go index b8811931243..f470444adc3 100644 --- a/libs/cmdio/teainput/press_test.go +++ b/libs/cmdio/teainput/press_test.go @@ -9,7 +9,7 @@ import ( func TestPressRoundTrips(t *testing.T) { for _, key := range []string{ - "enter", "ctrl+c", "ctrl+j", "ctrl+h", "backspace", "alt+backspace", + "enter", "alt+enter", "ctrl+c", "alt+ctrl+c", "ctrl+j", "ctrl+h", "backspace", "alt+backspace", "esc", "tab", "alt+tab", "shift+tab", "delete", "up", "down", "left", "right", "space", "alt+space", "q", "Q", "alt+f", "ctrl+n", "ctrl+p", } { diff --git a/libs/cmdio/teainput/teainput.go b/libs/cmdio/teainput/teainput.go index ea2dcebeac0..ef65f45905d 100644 --- a/libs/cmdio/teainput/teainput.go +++ b/libs/cmdio/teainput/teainput.go @@ -9,8 +9,6 @@ package teainput import ( - "strings" - tea "github.com/charmbracelet/bubbletea" ) @@ -32,9 +30,8 @@ type Event struct { // Decode returns the [Event] for a key press or paste message, and false for // every other message. // -// Alt is kept in the name only where the models have always treated it as a -// different key (Alt+rune, Alt+space, Alt+backspace, Alt+tab). Other Alt -// combinations act as the plain key, as they did before the decoder existed. +// Alt stays in the name, so Alt+Enter is "alt+enter" and no model matches it +// unless it names it. Alt+rune and Alt+space carry no text. func Decode(msg tea.Msg) (Event, bool) { k, ok := msg.(tea.KeyMsg) if !ok { @@ -66,10 +63,10 @@ func Decode(msg tea.Msg) (Event, bool) { return printable(" "), true case tea.KeyBackspace, tea.KeyTab: if k.Alt { - return Event{Key: k.String()}, true // "alt+backspace", "alt+tab" + return Event{Key: k.String()}, true } } - return Event{Key: strings.TrimPrefix(k.String(), "alt+")}, true + return Event{Key: k.String()}, true } // printable is the event for one typed rune: its key name is the rune, or diff --git a/libs/cmdio/teainput/teainput_test.go b/libs/cmdio/teainput/teainput_test.go index 79514761591..29acd746184 100644 --- a/libs/cmdio/teainput/teainput_test.go +++ b/libs/cmdio/teainput/teainput_test.go @@ -32,10 +32,9 @@ func TestDecode(t *testing.T) { {"shift+tab", tea.KeyMsg{Type: tea.KeyShiftTab}, teainput.Event{Key: "shift+tab"}}, {"delete", tea.KeyMsg{Type: tea.KeyDelete}, teainput.Event{Key: "delete"}}, {"up", tea.KeyMsg{Type: tea.KeyUp}, teainput.Event{Key: "up"}}, - // Alt on keys the models always treated as plain keys is dropped. - {"alt enter", tea.KeyMsg{Type: tea.KeyEnter, Alt: true}, teainput.Event{Key: "enter"}}, - {"alt ctrl+c", tea.KeyMsg{Type: tea.KeyCtrlC, Alt: true}, teainput.Event{Key: "ctrl+c"}}, - {"alt left", tea.KeyMsg{Type: tea.KeyLeft, Alt: true}, teainput.Event{Key: "left"}}, + {"alt enter", tea.KeyMsg{Type: tea.KeyEnter, Alt: true}, teainput.Event{Key: "alt+enter"}}, + {"alt ctrl+c", tea.KeyMsg{Type: tea.KeyCtrlC, Alt: true}, teainput.Event{Key: "alt+ctrl+c"}}, + {"alt left", tea.KeyMsg{Type: tea.KeyLeft, Alt: true}, teainput.Event{Key: "alt+left"}}, // Several runes in one read are text. They carry no key name, so a burst // that spells a key name is typed, not pressed. {"burst", tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("jk")}, teainput.Event{Text: "jk"}}, diff --git a/libs/tableview/tableview.go b/libs/tableview/tableview.go index 4662f4b638e..f1b266f7cc3 100644 --- a/libs/tableview/tableview.go +++ b/libs/tableview/tableview.go @@ -11,6 +11,7 @@ import ( "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/databricks/cli/libs/cmdio/teainput" "github.com/databricks/cli/libs/cmdio" ) @@ -219,12 +220,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.Height = height } return m, nil + } - case tea.KeyMsg: + if in, ok := teainput.Decode(msg); ok { if m.searching { - return m.updateSearch(msg) + return m.updateSearch(in) } - return m.updateNormal(msg) + return m.updateNormal(msg, in.Key) } var cmd tea.Cmd @@ -232,8 +234,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func (m model) updateNormal(msg tea.KeyMsg) (tea.Model, tea.Cmd) { - switch msg.String() { +// updateNormal handles a key outside search mode. msg is the raw message, +// passed on to the viewport for keys the table doesn't handle itself. +func (m model) updateNormal(msg tea.Msg, key string) (tea.Model, tea.Cmd) { + switch key { case "q", "esc", "ctrl+c": return m, tea.Quit case "/": @@ -266,7 +270,7 @@ func (m model) updateNormal(msg tea.KeyMsg) (tea.Model, tea.Cmd) { case "pgup", "b": m.moveCursor(-m.viewport.Height) return m, nil - case "pgdown", "f", " ": + case "pgdown", "f", "space": m.moveCursor(m.viewport.Height) return m, nil case "g": @@ -307,8 +311,8 @@ func (m *model) scrollToCursor() { } } -func (m model) updateSearch(msg tea.KeyMsg) (tea.Model, tea.Cmd) { - switch msg.String() { +func (m model) updateSearch(in teainput.Event) (tea.Model, tea.Cmd) { + switch in.Key { case "enter": m.searching = false m.searchQuery = m.searchInput @@ -335,10 +339,8 @@ func (m model) updateSearch(msg tea.KeyMsg) (tea.Model, tea.Cmd) { } return m, nil default: - // Only accept printable characters. - if len(msg.String()) == 1 || msg.Type == tea.KeyRunes { - m.searchInput += msg.String() - } + // Only accept printable characters (typed or pasted). + m.searchInput += in.Text return m, nil } } From 21cecc5f738dd65ba524f87791857e1b3650dc2b Mon Sep 17 00:00:00 2001 From: "pieter.noordhuis" Date: Tue, 17 Nov 2026 22:29:15 +0000 Subject: [PATCH 2/2] Link changelog fragments to the PR Co-authored-by: Isaac --- .nextchanges/cli/alt-keys-inert.md | 3 +-- .nextchanges/cli/paste-as-text.md | 1 + libs/tableview/tableview.go | 5 +++-- libs/tableview/tableview_test.go | 10 ++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .nextchanges/cli/paste-as-text.md diff --git a/.nextchanges/cli/alt-keys-inert.md b/.nextchanges/cli/alt-keys-inert.md index 08e41aee2d3..bca03b646a0 100644 --- a/.nextchanges/cli/alt-keys-inert.md +++ b/.nextchanges/cli/alt-keys-inert.md @@ -1,2 +1 @@ -* Alt with a key that isn't a letter (Alt+Enter, Alt+arrows, Alt+Space) no longer acts as that key in prompts, selection lists and the pager. Alt+Enter used to submit and Alt+Left used to move the cursor. -* Selection lists treat pasted text as typed search text, and ignore it outside search. Pasting `j` or `/` no longer moves the cursor or opens search. The table view's search no longer inserts `alt+f` for Alt+F or `[text]` for a paste. +* Alt with a key that isn't a letter (Alt+Enter, Alt+arrows, Alt+Space) no longer acts as that key in prompts, selection lists and the pager. Alt+Enter used to submit and Alt+Left used to move the cursor. ([#7741](https://github.com/databricks/cli/pull/7741)) diff --git a/.nextchanges/cli/paste-as-text.md b/.nextchanges/cli/paste-as-text.md new file mode 100644 index 00000000000..2f6cc0838c2 --- /dev/null +++ b/.nextchanges/cli/paste-as-text.md @@ -0,0 +1 @@ +* Selection lists treat pasted text as typed search text, and ignore it outside search. Pasting `j` or `/` no longer moves the cursor or opens search. The table view's search no longer inserts `alt+f` for Alt+F or `[text]` for a paste. ([#7741](https://github.com/databricks/cli/pull/7741)) diff --git a/libs/tableview/tableview.go b/libs/tableview/tableview.go index f1b266f7cc3..9777a483b59 100644 --- a/libs/tableview/tableview.go +++ b/libs/tableview/tableview.go @@ -7,6 +7,7 @@ import ( "io" "strings" "text/tabwriter" + "unicode/utf8" "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" @@ -334,8 +335,8 @@ func (m model) updateSearch(in teainput.Event) (tea.Model, tea.Cmd) { m.viewport.Height++ return m, nil case "backspace": - if len(m.searchInput) > 0 { - m.searchInput = m.searchInput[:len(m.searchInput)-1] + if _, size := utf8.DecodeLastRuneInString(m.searchInput); size > 0 { + m.searchInput = m.searchInput[:len(m.searchInput)-size] } return m, nil default: diff --git a/libs/tableview/tableview_test.go b/libs/tableview/tableview_test.go index 7d542a365b9..807d9f15ebd 100644 --- a/libs/tableview/tableview_test.go +++ b/libs/tableview/tableview_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/charmbracelet/bubbles/viewport" + "github.com/databricks/cli/libs/cmdio/teainput" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -117,3 +118,12 @@ func TestMoveCursorClampsAtZeroAndLast(t *testing.T) { m.moveCursor(100) assert.Equal(t, 2, m.cursor, "cursor should clamp to last data row") } + +func TestSearchBackspaceRemovesWholeRune(t *testing.T) { + m := readyModel([]string{"name"}, [][]string{{"café"}}, 5) + m.searching = true + m.searchInput = "café" + + next, _ := m.Update(teainput.Press("backspace")) + assert.Equal(t, "caf", next.(model).searchInput) +}