]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/search.go
Code optimisation (#1117)
[micro.git] / cmd / micro / search.go
index 91b8634556d881176e0e6e80669ce6c6dbba9d47..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
@@ -113,6 +118,8 @@ func searchDown(r *regexp.Regexp, v *View, start, end Loc) bool {
                if match != nil {
                        v.Cursor.SetSelectionStart(Loc{charPos + runePos(match[0], string(l)), i})
                        v.Cursor.SetSelectionEnd(Loc{charPos + runePos(match[1], string(l)), i})
+                       v.Cursor.OrigSelection[0] = v.Cursor.CurSelection[0]
+                       v.Cursor.OrigSelection[1] = v.Cursor.CurSelection[1]
                        v.Cursor.Loc = v.Cursor.CurSelection[1]
 
                        return true
@@ -140,6 +147,8 @@ func searchUp(r *regexp.Regexp, v *View, start, end Loc) bool {
                if match != nil {
                        v.Cursor.SetSelectionStart(Loc{runePos(match[0], string(l)), i})
                        v.Cursor.SetSelectionEnd(Loc{runePos(match[1], string(l)), i})
+                       v.Cursor.OrigSelection[0] = v.Cursor.CurSelection[0]
+                       v.Cursor.OrigSelection[1] = v.Cursor.CurSelection[1]
                        v.Cursor.Loc = v.Cursor.CurSelection[1]
 
                        return true
@@ -175,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()
        }
 }