mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Add support for control-A and control-E shortcuts similar to GNU readline
This commit is contained in:
parent
87c2cde688
commit
0a76c875e4
@ -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{
|
||||
|
1
client/testdata/TestTui-JumpCursor
vendored
Normal file
1
client/testdata/TestTui-JumpCursor
vendored
Normal file
@ -0,0 +1 @@
|
||||
Search Query: > AAAfooZZZ
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user