]> git.lizzy.rs Git - micro.git/commitdiff
find: prefill with selection (#2115)
authorAli Kefia <alikefia@users.noreply.github.com>
Wed, 2 Jun 2021 20:04:31 +0000 (22:04 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Jun 2021 20:04:31 +0000 (16:04 -0400)
* find: prefill with selection

* keep search func - could be used in plugins

internal/action/actions.go

index beb63b077dbd9098ed11e5516e6cb62bdd6fc510..892bc5555f33a3f68e38f86b9a73bef3a3a056c1 100644 (file)
@@ -903,7 +903,7 @@ func (h *BufPane) find(useRegex bool) bool {
                        h.Relocate()
                }
        }
-       InfoBar.Prompt(prompt, "", "Find", eventCallback, func(resp string, canceled bool) {
+       findCallback := func(resp string, canceled bool) {
                // Finished callback
                if !canceled {
                        match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex)
@@ -926,8 +926,12 @@ func (h *BufPane) find(useRegex bool) bool {
                        h.Cursor.ResetSelection()
                }
                h.Relocate()
-       })
-
+       }
+       pattern := string(h.Cursor.GetSelection())
+       if eventCallback != nil && pattern != "" {
+               eventCallback(pattern)
+       }
+       InfoBar.Prompt(prompt, pattern, "Find", eventCallback, findCallback)
        return true
 }