mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-16 05:47:06 +09:00
Fix some search bugs
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
@@ -69,7 +70,14 @@ func InitFlags() {
|
|||||||
|
|
||||||
if *flagOptions {
|
if *flagOptions {
|
||||||
// If -options was passed
|
// 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("-%s value\n", k)
|
||||||
fmt.Printf(" \tDefault value: '%v'\n", v)
|
fmt.Printf(" \tDefault value: '%v'\n", v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -599,21 +599,25 @@ func (h *BufPane) saveBufToFile(filename string) {
|
|||||||
|
|
||||||
// Find opens a prompt and searches forward for the input
|
// Find opens a prompt and searches forward for the input
|
||||||
func (h *BufPane) Find() bool {
|
func (h *BufPane) Find() bool {
|
||||||
|
h.searchOrig = h.Cursor.Loc
|
||||||
InfoBar.Prompt("Find: ", "", "Find", func(resp string) {
|
InfoBar.Prompt("Find: ", "", "Find", func(resp string) {
|
||||||
// Event callback
|
// 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 {
|
if found {
|
||||||
h.Cursor.SetSelectionStart(match[0])
|
h.Cursor.SetSelectionStart(match[0])
|
||||||
h.Cursor.SetSelectionEnd(match[1])
|
h.Cursor.SetSelectionEnd(match[1])
|
||||||
h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0]
|
h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0]
|
||||||
h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1]
|
h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1]
|
||||||
|
h.Cursor.GotoLoc(match[1])
|
||||||
} else {
|
} else {
|
||||||
|
h.Cursor.GotoLoc(h.searchOrig)
|
||||||
h.Cursor.ResetSelection()
|
h.Cursor.ResetSelection()
|
||||||
}
|
}
|
||||||
|
h.Relocate()
|
||||||
}, func(resp string, canceled bool) {
|
}, func(resp string, canceled bool) {
|
||||||
// Finished callback
|
// Finished callback
|
||||||
if !canceled {
|
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 {
|
if err != nil {
|
||||||
InfoBar.Error(err)
|
InfoBar.Error(err)
|
||||||
}
|
}
|
||||||
@@ -622,7 +626,7 @@ func (h *BufPane) Find() bool {
|
|||||||
h.Cursor.SetSelectionEnd(match[1])
|
h.Cursor.SetSelectionEnd(match[1])
|
||||||
h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0]
|
h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0]
|
||||||
h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1]
|
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
|
h.lastSearch = resp
|
||||||
} else {
|
} else {
|
||||||
h.Cursor.ResetSelection()
|
h.Cursor.ResetSelection()
|
||||||
@@ -631,9 +635,10 @@ func (h *BufPane) Find() bool {
|
|||||||
} else {
|
} else {
|
||||||
h.Cursor.ResetSelection()
|
h.Cursor.ResetSelection()
|
||||||
}
|
}
|
||||||
|
h.Relocate()
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindNext searches forwards for the last used search term
|
// FindNext searches forwards for the last used search term
|
||||||
|
|||||||
@@ -104,6 +104,9 @@ type BufPane struct {
|
|||||||
multiWord bool
|
multiWord bool
|
||||||
|
|
||||||
splitID uint64
|
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 {
|
func NewBufPane(buf *buffer.Buffer, win display.BWindow) *BufPane {
|
||||||
|
|||||||
@@ -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 {
|
if i == start.Y && start.Y == end.Y {
|
||||||
nchars := utf8.RuneCount(l)
|
nchars := utf8.RuneCount(l)
|
||||||
start.X = util.Clamp(start.X, 0, nchars-1)
|
start.X = util.Clamp(start.X, 0, nchars)
|
||||||
end.X = util.Clamp(end.X, 0, nchars-1)
|
end.X = util.Clamp(end.X, 0, nchars)
|
||||||
l = util.SliceStart(l, end.X)
|
l = util.SliceStart(l, end.X)
|
||||||
l = util.SliceEnd(l, start.X)
|
l = util.SliceEnd(l, start.X)
|
||||||
charpos = start.X
|
charpos = start.X
|
||||||
} else if i == start.Y {
|
} else if i == start.Y {
|
||||||
nchars := utf8.RuneCount(l)
|
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)
|
l = util.SliceEnd(l, start.X)
|
||||||
charpos = start.X
|
charpos = start.X
|
||||||
} else if i == end.Y {
|
} else if i == end.Y {
|
||||||
nchars := utf8.RuneCount(l)
|
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)
|
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 {
|
if i == start.Y && start.Y == end.Y {
|
||||||
nchars := utf8.RuneCount(l)
|
nchars := utf8.RuneCount(l)
|
||||||
start.X = util.Clamp(start.X, 0, nchars-1)
|
start.X = util.Clamp(start.X, 0, nchars)
|
||||||
end.X = util.Clamp(end.X, 0, nchars-1)
|
end.X = util.Clamp(end.X, 0, nchars)
|
||||||
l = util.SliceStart(l, end.X)
|
l = util.SliceStart(l, end.X)
|
||||||
l = util.SliceEnd(l, start.X)
|
l = util.SliceEnd(l, start.X)
|
||||||
charpos = start.X
|
charpos = start.X
|
||||||
} else if i == start.Y {
|
} else if i == start.Y {
|
||||||
nchars := utf8.RuneCount(l)
|
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)
|
l = util.SliceEnd(l, start.X)
|
||||||
charpos = start.X
|
charpos = start.X
|
||||||
} else if i == end.Y {
|
} else if i == end.Y {
|
||||||
nchars := utf8.RuneCount(l)
|
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)
|
l = util.SliceStart(l, end.X)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user