]> git.lizzy.rs Git - micro.git/commitdiff
Sort suggestions and cycle back
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 25 Jan 2019 03:10:57 +0000 (22:10 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 25 Dec 2019 22:05:10 +0000 (17:05 -0500)
cmd/micro/action/infocomplete.go
cmd/micro/action/infopane.go
cmd/micro/buffer/autocomplete.go

index 99a3844a8d132f23eb7a062ec3a68fb387856352..28d701e6b8c0a0695ad27d5b0f8c5cbc7c226a75 100644 (file)
@@ -2,6 +2,7 @@ package action
 
 import (
        "bytes"
+       "sort"
        "strings"
 
        "github.com/zyedidia/micro/cmd/micro/buffer"
@@ -25,6 +26,7 @@ func CommandComplete(b *buffer.Buffer) ([]string, []string) {
                }
        }
 
+       sort.Strings(suggestions)
        completions := make([]string, len(suggestions))
        for i := range suggestions {
                completions[i] = util.SliceEndStr(suggestions[i], c.X-argstart)
@@ -47,6 +49,7 @@ func HelpComplete(b *buffer.Buffer) ([]string, []string) {
                }
        }
 
+       sort.Strings(suggestions)
        completions := make([]string, len(suggestions))
        for i := range suggestions {
                completions[i] = util.SliceEndStr(suggestions[i], c.X-argstart)
@@ -101,6 +104,7 @@ func OptionComplete(b *buffer.Buffer) ([]string, []string) {
                }
        }
 
+       sort.Strings(suggestions)
        completions := make([]string, len(suggestions))
        for i := range suggestions {
                completions[i] = util.SliceEndStr(suggestions[i], c.X-argstart)
@@ -185,6 +189,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
                        }
                }
        }
+       sort.Strings(suggestions)
 
        completions := make([]string, len(suggestions))
        for i := range suggestions {
index 406476bc36c5af01bac3402f03812bcfb45cd46a..975d9f6ea4cc8d141b1cb572ad95e8f784565e22 100644 (file)
@@ -151,6 +151,7 @@ var InfoOverrides = map[string]InfoKeyAction{
        "CursorDown":    (*InfoPane).CursorDown,
        "InsertNewline": (*InfoPane).InsertNewline,
        "InsertTab":     (*InfoPane).InsertTab,
+       "OutdentLine":   (*InfoPane).CycleBack,
        "Escape":        (*InfoPane).Escape,
        "Quit":          (*InfoPane).Quit,
        "QuitAll":       (*InfoPane).QuitAll,
@@ -165,7 +166,7 @@ func (h *InfoPane) CursorDown() {
 func (h *InfoPane) InsertTab() {
        b := h.Buf
        if b.HasSuggestions {
-               b.CycleAutocomplete()
+               b.CycleAutocomplete(true)
                return
        }
 
@@ -186,6 +187,11 @@ func (h *InfoPane) InsertTab() {
                }
        }
 }
+func (h *InfoPane) CycleBack() {
+       if h.Buf.HasSuggestions {
+               h.Buf.CycleAutocomplete(false)
+       }
+}
 func (h *InfoPane) InsertNewline() {
        if !h.HasYN {
                h.DonePrompt(false)
index 12dbc0b52c9165785847a8e22d36a9449de22597..7ac0d983bb4d4b3a5de2b3485d4dc2195bd4d886 100644 (file)
@@ -4,6 +4,7 @@ import (
        "bytes"
        "io/ioutil"
        "os"
+       "sort"
        "strings"
        "unicode/utf8"
 
@@ -29,15 +30,21 @@ func (b *Buffer) Autocomplete(c Completer) {
                return
        }
        b.CurSuggestion = -1
-       b.CycleAutocomplete()
+       b.CycleAutocomplete(true)
 }
 
-func (b *Buffer) CycleAutocomplete() {
+func (b *Buffer) CycleAutocomplete(forward bool) {
        prevSuggestion := b.CurSuggestion
 
-       b.CurSuggestion++
-       if b.CurSuggestion >= len(b.Suggestions) || b.CurSuggestion < 0 {
+       if forward {
+               b.CurSuggestion++
+       } else {
+               b.CurSuggestion--
+       }
+       if b.CurSuggestion >= len(b.Suggestions) {
                b.CurSuggestion = 0
+       } else if b.CurSuggestion < 0 {
+               b.CurSuggestion = len(b.Suggestions) - 1
        }
 
        c := b.GetActiveCursor()
@@ -105,6 +112,7 @@ func FileComplete(b *Buffer) ([]string, []string) {
                }
        }
 
+       sort.Strings(suggestions)
        completions := make([]string, len(suggestions))
        for i := range suggestions {
                var complete string