diff --git a/client/client_test.go b/client/client_test.go index f312f41..fa18b84 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2089,6 +2089,14 @@ func testTui_general(t *testing.T, onlineStatus OnlineStatus) { out = strings.Split(stripTuiCommandPrefix(t, out), "\n")[0] testutils.CompareGoldens(t, out, "TestTui-SelectAndCd") + // Test jumping around the cursor via shortcuts + out = captureTerminalOutput(t, tester, []string{ + "hishtory SPACE tquery ENTER", + "foo C-a AAA C-e ZZZ", + }) + out = strings.Split(stripTuiCommandPrefix(t, out), "\n")[0] + testutils.CompareGoldens(t, out, "TestTui-JumpCursor") + // Test the User column tester.RunInteractiveShell(t, `hishtory config-add displayed-columns User`) out = captureTerminalOutput(t, tester, []string{ diff --git a/client/testdata/TestTui-JumpCursor b/client/testdata/TestTui-JumpCursor new file mode 100644 index 0000000..e97fefa --- /dev/null +++ b/client/testdata/TestTui-JumpCursor @@ -0,0 +1 @@ +Search Query: > AAAfooZZZ \ No newline at end of file diff --git a/client/tui/tui.go b/client/tui/tui.go index e92cce8..6195b8f 100644 --- a/client/tui/tui.go +++ b/client/tui/tui.go @@ -56,6 +56,8 @@ type keyMap struct { DeleteEntry key.Binding Help key.Binding Quit key.Binding + JumpStartOfInput key.Binding + JumpEndOfInput key.Binding } var fakeTitleKeyBinding key.Binding = key.NewBinding( @@ -134,6 +136,14 @@ var keys = keyMap{ key.WithKeys("esc", "ctrl+c", "ctrl+d"), key.WithHelp("esc", "exit hiSHtory "), ), + JumpStartOfInput: key.NewBinding( + key.WithKeys("ctrl+a"), + key.WithHelp("ctrl+a", "jump to the start of the input "), + ), + JumpEndOfInput: key.NewBinding( + key.WithKeys("ctrl+e"), + key.WithHelp("ctrl+e", "jump to the end of the input "), + ), } type SelectStatus int64 @@ -341,6 +351,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, keys.Help): m.help.ShowAll = !m.help.ShowAll return m, nil + case key.Matches(msg, keys.JumpStartOfInput): + m.queryInput.SetCursor(0) + return m, nil + case key.Matches(msg, keys.JumpEndOfInput): + m.queryInput.SetCursor(len(m.queryInput.Value())) + return m, nil default: pendingCommands := tea.Batch() if m.table != nil {