Skip to content

Commit 762e31f

Browse files
authored
Merge pull request zyedidia#3333 from masmu/feature/reset-search
Implemented `ResetSearch` and allow action chaining of `FindNext` and `FindPrevious`
2 parents 1f71667 + bbf6ec2 commit 762e31f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

internal/action/actions.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,20 @@ func (h *BufPane) UnhighlightSearch() bool {
10721072
return true
10731073
}
10741074

1075+
// ResetSearch resets the last used search term
1076+
func (h *BufPane) ResetSearch() bool {
1077+
if h.Buf.LastSearch != "" {
1078+
h.Buf.LastSearch = ""
1079+
return true
1080+
}
1081+
return false
1082+
}
1083+
10751084
// FindNext searches forwards for the last used search term
10761085
func (h *BufPane) FindNext() bool {
1086+
if h.Buf.LastSearch == "" {
1087+
return false
1088+
}
10771089
// If the cursor is at the start of a selection and we search we want
10781090
// to search from the end of the selection in the case that
10791091
// the selection is a search result in which case we wouldn't move at
@@ -1100,6 +1112,9 @@ func (h *BufPane) FindNext() bool {
11001112

11011113
// FindPrevious searches backwards for the last used search term
11021114
func (h *BufPane) FindPrevious() bool {
1115+
if h.Buf.LastSearch == "" {
1116+
return false
1117+
}
11031118
// If the cursor is at the end of a selection and we search we want
11041119
// to search from the beginning of the selection in the case that
11051120
// the selection is a search result in which case we wouldn't move at

internal/action/bufpane.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ var BufKeyActions = map[string]BufKeyAction{
811811
"ToggleRuler": (*BufPane).ToggleRuler,
812812
"ToggleHighlightSearch": (*BufPane).ToggleHighlightSearch,
813813
"UnhighlightSearch": (*BufPane).UnhighlightSearch,
814+
"ResetSearch": (*BufPane).ResetSearch,
814815
"ClearStatus": (*BufPane).ClearStatus,
815816
"ShellMode": (*BufPane).ShellMode,
816817
"CommandMode": (*BufPane).CommandMode,

runtime/help/keybindings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ ToggleHelp
241241
ToggleDiffGutter
242242
ToggleRuler
243243
JumpLine
244+
ResetSearch
244245
ClearStatus
245246
ShellMode
246247
CommandMode

0 commit comments

Comments
 (0)