diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 83eec1440..beb085cea 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -1075,14 +1075,13 @@ func (v *View) FindNext(usePlugin bool) bool { if v.Cursor.HasSelection() { searchStart = v.Cursor.CurSelection[1] - // lastSearch = v.Cursor.GetSelection() } else { searchStart = v.Cursor.Loc } if lastSearch == "" { return true } - messenger.Message("Finding: " + lastSearch) + messenger.Message("Searched next: " + lastSearch) Search(lastSearch, v, true) if usePlugin { @@ -1102,7 +1101,7 @@ func (v *View) FindPrevious(usePlugin bool) bool { } else { searchStart = v.Cursor.Loc } - messenger.Message("Finding: " + lastSearch) + messenger.Message("Searched previous: " + lastSearch) Search(lastSearch, v, false) if usePlugin { @@ -1819,11 +1818,6 @@ func (v *View) ToggleOverwriteMode(usePlugin bool) bool { // Escape leaves current mode func (v *View) Escape(usePlugin bool) bool { if v.mainCursor() { - // check if user is searching, or the last search is still active - if searching || lastSearch != "" { - ExitSearch(v) - return true - } // check if a prompt is shown, hide it and don't quit if messenger.hasPrompt { messenger.Reset() // FIXME diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index e3a028417..c8f5191f7 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -17,6 +17,8 @@ var mouseBindings map[Key][]func(*View, bool, *tcell.EventMouse) bool var helpBinding string var kmenuBinding string +var reverseBindingKeys map[tcell.Key]string + var mouseBindingActions = map[string]func(*View, bool, *tcell.EventMouse) bool{ "MousePress": (*View).MousePress, "MouseMultiCursor": (*View).MouseMultiCursor, @@ -279,6 +281,11 @@ func InitBindings() { bindingsStr = make(map[string]string) mouseBindings = make(map[Key][]func(*View, bool, *tcell.EventMouse) bool) + reverseBindingKeys = make(map[tcell.Key]string) + for k, v := range bindingKeys { + reverseBindingKeys[v] = k + } + var parsed map[string]string defaults := DefaultBindings() diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index f9142af77..dd25be928 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -521,7 +521,7 @@ func main() { t.Resize() } case *tcell.EventMouse: - if !searching { + // if !searching { if e.Buttons() == tcell.Button1 { // If the user left clicked we check a couple things _, h := screen.Size() @@ -557,7 +557,7 @@ func main() { didAction = true } } - } + // } } if !didAction { diff --git a/cmd/micro/search.go b/cmd/micro/search.go index 139bcb417..2619a9dd8 100644 --- a/cmd/micro/search.go +++ b/cmd/micro/search.go @@ -46,7 +46,6 @@ func EndSearch() { // ExitSearch exits the search mode, reset active search phrase, and clear status bar func ExitSearch(v *View) { - lastSearch = "" searching = false messenger.hasPrompt = false messenger.Clear() @@ -59,6 +58,21 @@ func ExitSearch(v *View) { func HandleSearchEvent(event tcell.Event, v *View) { switch e := event.(type) { case *tcell.EventKey: + + // Handle FindNext and FindPrevious while composing search + switch bindingsStr[reverseBindingKeys[e.Key()]] { + case "Find", "FindNext": + lastSearch = messenger.response + v.FindNext(true) + v.Relocate() + return + case "FindPrevious": + lastSearch = messenger.response + v.FindPrevious(true) + v.Relocate() + return + } + switch e.Key() { case tcell.KeyEscape: // Exit the search mode @@ -74,6 +88,10 @@ func HandleSearchEvent(event tcell.Event, v *View) { EndSearch() return } + // Do nothing on mouse events. + // Prevents relocating on mouse motion, so we can scroll the view while searching. + case *tcell.EventMouse: + return } messenger.HandleEvent(event, searchHistory)