diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 9799ef70..230c62c0 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "sort" "strings" "github.com/go-errors/errors" @@ -69,7 +70,14 @@ func InitFlags() { if *flagOptions { // If -options was passed - for k, v := range config.DefaultGlobalSettings() { + var keys []string + m := config.DefaultGlobalSettings() + for k, _ := range m { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { + v := m[k] fmt.Printf("-%s value\n", k) fmt.Printf(" \tDefault value: '%v'\n", v) } diff --git a/internal/action/actions.go b/internal/action/actions.go index 3ecce1aa..846489d4 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -599,21 +599,25 @@ func (h *BufPane) saveBufToFile(filename string) { // Find opens a prompt and searches forward for the input func (h *BufPane) Find() bool { + h.searchOrig = h.Cursor.Loc InfoBar.Prompt("Find: ", "", "Find", func(resp string) { // Event callback - match, found, _ := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.Cursor.Loc, true, true) + match, found, _ := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, true) if found { h.Cursor.SetSelectionStart(match[0]) h.Cursor.SetSelectionEnd(match[1]) h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0] h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1] + h.Cursor.GotoLoc(match[1]) } else { + h.Cursor.GotoLoc(h.searchOrig) h.Cursor.ResetSelection() } + h.Relocate() }, func(resp string, canceled bool) { // Finished callback if !canceled { - match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.Cursor.Loc, true, true) + match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, true) if err != nil { InfoBar.Error(err) } @@ -622,7 +626,7 @@ func (h *BufPane) Find() bool { h.Cursor.SetSelectionEnd(match[1]) h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0] h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1] - h.Cursor.Loc = h.Cursor.CurSelection[1] + h.Cursor.GotoLoc(h.Cursor.CurSelection[1]) h.lastSearch = resp } else { h.Cursor.ResetSelection() @@ -631,9 +635,10 @@ func (h *BufPane) Find() bool { } else { h.Cursor.ResetSelection() } + h.Relocate() }) - return true + return false } // FindNext searches forwards for the last used search term diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 87f06d5c..ae6d56ce 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -104,6 +104,9 @@ type BufPane struct { multiWord bool splitID uint64 + + // remember original location of a search in case the search is canceled + searchOrig buffer.Loc } func NewBufPane(buf *buffer.Buffer, win display.BWindow) *BufPane { diff --git a/internal/buffer/search.go b/internal/buffer/search.go index 587ca5e9..4382971d 100644 --- a/internal/buffer/search.go +++ b/internal/buffer/search.go @@ -21,19 +21,19 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) { if i == start.Y && start.Y == end.Y { nchars := utf8.RuneCount(l) - start.X = util.Clamp(start.X, 0, nchars-1) - end.X = util.Clamp(end.X, 0, nchars-1) + start.X = util.Clamp(start.X, 0, nchars) + end.X = util.Clamp(end.X, 0, nchars) l = util.SliceStart(l, end.X) l = util.SliceEnd(l, start.X) charpos = start.X } else if i == start.Y { nchars := utf8.RuneCount(l) - start.X = util.Clamp(start.X, 0, nchars-1) + start.X = util.Clamp(start.X, 0, nchars) l = util.SliceEnd(l, start.X) charpos = start.X } else if i == end.Y { nchars := utf8.RuneCount(l) - end.X = util.Clamp(end.X, 0, nchars-1) + end.X = util.Clamp(end.X, 0, nchars) l = util.SliceStart(l, end.X) } @@ -62,19 +62,19 @@ func (b *Buffer) findUp(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) { if i == start.Y && start.Y == end.Y { nchars := utf8.RuneCount(l) - start.X = util.Clamp(start.X, 0, nchars-1) - end.X = util.Clamp(end.X, 0, nchars-1) + start.X = util.Clamp(start.X, 0, nchars) + end.X = util.Clamp(end.X, 0, nchars) l = util.SliceStart(l, end.X) l = util.SliceEnd(l, start.X) charpos = start.X } else if i == start.Y { nchars := utf8.RuneCount(l) - start.X = util.Clamp(start.X, 0, nchars-1) + start.X = util.Clamp(start.X, 0, nchars) l = util.SliceEnd(l, start.X) charpos = start.X } else if i == end.Y { nchars := utf8.RuneCount(l) - end.X = util.Clamp(end.X, 0, nchars-1) + end.X = util.Clamp(end.X, 0, nchars) l = util.SliceStart(l, end.X) }