Repository navigation
cmdio: make Alt+non-letter keys inert and route paste as text #7741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +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. ([#7741](https://github.com/databricks/cli/pull/7741)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Value: ab | ||
| ✔ Value: abc█ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| value: "ab" | ||
| value: "abc" | ||
| err: <nil> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ✔ Value: abX█ | ||
| ✔ Value: abcX█ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| value: "abXc" | ||
| value: "abcX" | ||
| err: <nil> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
|
|
||
| Search: █ | ||
| ? Pick one: | ||
| alpha | ||
| beta (id-02) | ||
| gamma |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,4 +37,4 @@ item-20 ready | |
|
|
||
|
|
||
| 20 rows | ||
| / italt+f[em-1]█ | ||
| / item-1█ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,12 @@ import ( | |
| "io" | ||
| "strings" | ||
| "text/tabwriter" | ||
| "unicode/utf8" | ||
|
|
||
| "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,21 +221,24 @@ 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] A paste in normal mode has if in, ok := teainput.Decode(msg); ok {
if in.Paste {
if m.searching && in.Text != "" {
m.searchInput += in.Text
}
return m, nil
}
...
} |
||
| } | ||
|
|
||
| var cmd tea.Cmd | ||
| m.viewport, cmd = m.viewport.Update(msg) | ||
| 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 +271,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 +312,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 | ||
|
|
@@ -330,15 +335,13 @@ func (m model) updateSearch(msg tea.KeyMsg) (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: | ||
| // 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 | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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 theupdateNormalswitch falls through andm.viewport.Update(msg)receives the rawtea.KeyMsg. If the viewport has a key binding that matches the pasted text (e.g. a single pasted"d"hittingHalfPageDown), it would scroll. Can we add a paste guard here like the other two models?