Implemented ResetSearch and allow action chaining of FindNext and FindPrevious by masmu · Pull Request #3333 · micro-editor/micro (original) (raw)

This is a small feature to reset previously initiated searches and to use FindNext and FindPrevious in chained actions.

Personally I never could get used to use different shortcuts for initiating and continuing a search. (First Ctrl-f, then Ctrl-n or Ctrl-p)

Assuming that the option hlsearch is set to false, my preferred workflow is:

To achieve this chaining actions seems like the way to go. Like:

"Ctrl-f": "Find",
"Enter": "FindNext|InsertNewline",

But this didn't work, since BufPane.FindNext() and BufPane.FindPrevious() always return true, which prevents all subsequent actions from being executed.
I'm not sure if this is intentional for some reason. It seems more likely that this case was omitted or forgotten because it generally excludes the possibility of chaining actions.
Buffer.FindNext() handles the case of a search term being empty. But it would also reset the selection when adding a return false there.
So adding a guard clause at the top of the function may be the best solution and should not break any potential user bindings out there.

The missing piece left was to add ResetSearch() which allows to exit a previously initiated search. Like:

"Esc": "ResetSearch|RemoveAllMultiCursors|Escape",

Just as a bonus:
The following snippet adds a visual representation for being in search mode to the status line, which is IMHO quite nice.

micro.SetStatusInfoFn("initlua.tabSearch")

function tabSearch(buf) if buf.LastSearch == '' then return '' end return string.format(' [search=%s]', buf.LastSearch) end