]> git.lizzy.rs Git - micro.git/commitdiff
search: Only update lastSearch on ENTER
authorPranav Raja <rickdangerous1@gmail.com>
Mon, 16 Oct 2017 06:35:57 +0000 (17:35 +1100)
committerPranav Raja <rickdangerous1@gmail.com>
Mon, 16 Oct 2017 06:44:44 +0000 (17:44 +1100)
This has a few effects:

- `lastSearch` doesn't get overriden with partial searches
unnecessarily, which matches the behaviour of vim/emacs etc.

- Selecting a word, then pressing C-c C-f ENTER works better as you can
now use C-n and C-p to jump to more occurrences of what you just
searched for. Without this C-n would jump to what you searched for
*previously*.

- `lastSearch` will now be updated even if the search did not match -
again, this matches the behaviour of vim/emacs.

cmd/micro/search.go

index 8317fd0a9109a62672a676ea608458ecf6f4e339..139bcb4178e1be32a3a8c480b41f59c99ac47327 100644 (file)
@@ -64,7 +64,12 @@ func HandleSearchEvent(event tcell.Event, v *View) {
                        // Exit the search mode
                        ExitSearch(v)
                        return
-               case tcell.KeyCtrlQ, tcell.KeyCtrlC, tcell.KeyEnter:
+               case tcell.KeyEnter:
+                       // If the user has pressed Enter, they want this to be the lastSearch
+                       lastSearch = messenger.response
+                       EndSearch()
+                       return
+               case tcell.KeyCtrlQ, tcell.KeyCtrlC:
                        // Done
                        EndSearch()
                        return
@@ -179,9 +184,7 @@ func Search(searchStr string, v *View, down bool) {
                        found = searchUp(r, v, v.Buf.End(), searchStart)
                }
        }
-       if found {
-               lastSearch = searchStr
-       } else {
+       if !found {
                v.Cursor.ResetSelection()
        }
 }