From f4d576b6e09f9fa7851a595a338cf41b7ad08802 Mon Sep 17 00:00:00 2001 From: Massimo Mund Date: Sat, 8 Jun 2024 11:06:54 +0200 Subject: [PATCH 1/2] Allow action chaining of 'FindNext' and 'FindPrevious' --- internal/action/actions.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/action/actions.go b/internal/action/actions.go index 79bff07d..0dd5f5b8 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1074,6 +1074,9 @@ func (h *BufPane) UnhighlightSearch() bool { // FindNext searches forwards for the last used search term func (h *BufPane) FindNext() bool { + if h.Buf.LastSearch == "" { + return false + } // If the cursor is at the start of a selection and we search we want // to search from the end of the selection in the case that // the selection is a search result in which case we wouldn't move at @@ -1100,6 +1103,9 @@ func (h *BufPane) FindNext() bool { // FindPrevious searches backwards for the last used search term func (h *BufPane) FindPrevious() bool { + if h.Buf.LastSearch == "" { + return false + } // If the cursor is at the end of a selection and we search we want // to search from the beginning of the selection in the case that // the selection is a search result in which case we wouldn't move at From bbf6ec292ec300ebdf10f6f9d644f85454d781a1 Mon Sep 17 00:00:00 2001 From: Massimo Mund Date: Sat, 8 Jun 2024 11:08:38 +0200 Subject: [PATCH 2/2] Implemented 'ResetSearch' to allow a search to be resetted Added ResetSearch to the list of bindable actions in keybindings.md --- internal/action/actions.go | 9 +++++++++ internal/action/bufpane.go | 1 + runtime/help/keybindings.md | 1 + 3 files changed, 11 insertions(+) diff --git a/internal/action/actions.go b/internal/action/actions.go index 0dd5f5b8..28d0e53d 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1072,6 +1072,15 @@ func (h *BufPane) UnhighlightSearch() bool { return true } +// ResetSearch resets the last used search term +func (h *BufPane) ResetSearch() bool { + if h.Buf.LastSearch != "" { + h.Buf.LastSearch = "" + return true + } + return false +} + // FindNext searches forwards for the last used search term func (h *BufPane) FindNext() bool { if h.Buf.LastSearch == "" { diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 7b348b79..e9ff0fec 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -815,6 +815,7 @@ var BufKeyActions = map[string]BufKeyAction{ "ToggleRuler": (*BufPane).ToggleRuler, "ToggleHighlightSearch": (*BufPane).ToggleHighlightSearch, "UnhighlightSearch": (*BufPane).UnhighlightSearch, + "ResetSearch": (*BufPane).ResetSearch, "ClearStatus": (*BufPane).ClearStatus, "ShellMode": (*BufPane).ShellMode, "CommandMode": (*BufPane).CommandMode, diff --git a/runtime/help/keybindings.md b/runtime/help/keybindings.md index 17f9ab35..3198c8fb 100644 --- a/runtime/help/keybindings.md +++ b/runtime/help/keybindings.md @@ -241,6 +241,7 @@ ToggleHelp ToggleDiffGutter ToggleRuler JumpLine +ResetSearch ClearStatus ShellMode CommandMode