X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fsearch.go;h=139bcb4178e1be32a3a8c480b41f59c99ac47327;hb=71af765b4e4f368c4bbbcb3947f3497e17271b62;hp=91b8634556d881176e0e6e80669ce6c6dbba9d47;hpb=e4751fd84cb71ba032bdcb4fa4e7777b24b9bc1e;p=micro.git diff --git a/cmd/micro/search.go b/cmd/micro/search.go index 91b86345..139bcb41 100644 --- a/cmd/micro/search.go +++ b/cmd/micro/search.go @@ -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() } }