diff --git a/internal/action/actions.go b/internal/action/actions.go index d5571d09..c42b6c8a 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -802,10 +802,23 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func()) // Find opens a prompt and searches forward for the input func (h *BufPane) Find() bool { + return h.find(true) +} + +// FindLiteral is the same as Find() but does not support regular expressions +func (h *BufPane) FindLiteral() bool { + return h.find(false) +} + +func (h *BufPane) find(useRegex bool) bool { h.searchOrig = h.Cursor.Loc - InfoBar.Prompt("Find (regex): ", "", "Find", func(resp string) { + prompt := "Find: " + if useRegex { + prompt = "Find (regex): " + } + InfoBar.Prompt(prompt, "", "Find", func(resp string) { // Event callback - match, found, _ := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, true) + match, found, _ := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex) if found { h.Cursor.SetSelectionStart(match[0]) h.Cursor.SetSelectionEnd(match[1]) @@ -820,7 +833,7 @@ func (h *BufPane) Find() bool { }, func(resp string, canceled bool) { // Finished callback if !canceled { - match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, true) + match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex) if err != nil { InfoBar.Error(err) } @@ -831,6 +844,7 @@ func (h *BufPane) Find() bool { h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1] h.Cursor.GotoLoc(h.Cursor.CurSelection[1]) h.lastSearch = resp + h.lastSearchRegex = useRegex } else { h.Cursor.ResetSelection() InfoBar.Message("No matches found") @@ -854,7 +868,7 @@ func (h *BufPane) FindNext() bool { if h.Cursor.HasSelection() { searchLoc = h.Cursor.CurSelection[1] } - match, found, err := h.Buf.FindNext(h.lastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, true) + match, found, err := h.Buf.FindNext(h.lastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.lastSearchRegex) if err != nil { InfoBar.Error(err) } @@ -881,7 +895,7 @@ func (h *BufPane) FindPrevious() bool { if h.Cursor.HasSelection() { searchLoc = h.Cursor.CurSelection[0] } - match, found, err := h.Buf.FindNext(h.lastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, true) + match, found, err := h.Buf.FindNext(h.lastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.lastSearchRegex) if err != nil { InfoBar.Error(err) } diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 0daf8afd..d770c92d 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -180,6 +180,7 @@ type BufPane struct { // Last search stores the last successful search for FindNext and FindPrev lastSearch string + lastSearchRegex bool // Should the current multiple cursor selection search based on word or // based on selection (false for selection, true for word) multiWord bool @@ -552,6 +553,7 @@ var BufKeyActions = map[string]BufKeyAction{ "SaveAll": (*BufPane).SaveAll, "SaveAs": (*BufPane).SaveAs, "Find": (*BufPane).Find, + "FindLiteral": (*BufPane).FindLiteral, "FindNext": (*BufPane).FindNext, "FindPrevious": (*BufPane).FindPrevious, "Center": (*BufPane).Center, diff --git a/runtime/help/keybindings.md b/runtime/help/keybindings.md index b8f67064..cc185924 100644 --- a/runtime/help/keybindings.md +++ b/runtime/help/keybindings.md @@ -185,6 +185,7 @@ Save SaveAll SaveAs Find +FindLiteral FindNext FindPrevious Undo