forked from mirror/readline
durable mark
This commit is contained in:
parent
bc96fada95
commit
80af385185
25
search.go
25
search.go
|
@ -18,14 +18,16 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type opSearch struct {
|
type opSearch struct {
|
||||||
inMode bool
|
inMode bool
|
||||||
state int
|
state int
|
||||||
dir int
|
dir int
|
||||||
source *list.Element
|
source *list.Element
|
||||||
w io.Writer
|
w io.Writer
|
||||||
buf *RuneBuffer
|
buf *RuneBuffer
|
||||||
data []rune
|
data []rune
|
||||||
history *opHistory
|
history *opHistory
|
||||||
|
markStart int
|
||||||
|
markEnd int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOpSearch(w io.Writer, buf *RuneBuffer, history *opHistory) *opSearch {
|
func newOpSearch(w io.Writer, buf *RuneBuffer, history *opHistory) *opSearch {
|
||||||
|
@ -76,7 +78,7 @@ func (o *opSearch) search(isChange bool) bool {
|
||||||
idx += len(o.data)
|
idx += len(o.data)
|
||||||
}
|
}
|
||||||
o.buf.SetWithIdx(idx, item)
|
o.buf.SetWithIdx(idx, item)
|
||||||
o.buf.SetStyle(start, end, "4m")
|
o.markStart, o.markEnd = start, end
|
||||||
o.SearchRefresh(idx)
|
o.SearchRefresh(idx)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -103,6 +105,7 @@ func (o *opSearch) ExitSearchMode(revert bool) {
|
||||||
o.history.current = o.source
|
o.history.current = o.source
|
||||||
o.buf.Set(o.history.showItem(o.history.current.Value))
|
o.buf.Set(o.history.showItem(o.history.current.Value))
|
||||||
}
|
}
|
||||||
|
o.markStart, o.markEnd = 0, 0
|
||||||
o.state = S_STATE_FOUND
|
o.state = S_STATE_FOUND
|
||||||
o.inMode = false
|
o.inMode = false
|
||||||
o.source = nil
|
o.source = nil
|
||||||
|
@ -121,6 +124,10 @@ func (o *opSearch) SearchRefresh(x int) {
|
||||||
x += len(o.buf.prompt)
|
x += len(o.buf.prompt)
|
||||||
x = x % getWidth()
|
x = x % getWidth()
|
||||||
|
|
||||||
|
if o.markStart > 0 {
|
||||||
|
o.buf.SetStyle(o.markStart, o.markEnd, "4m")
|
||||||
|
}
|
||||||
|
|
||||||
lineCnt := o.buf.CursorLineCount()
|
lineCnt := o.buf.CursorLineCount()
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
buf.Write(bytes.Repeat([]byte("\n"), lineCnt))
|
buf.Write(bytes.Repeat([]byte("\n"), lineCnt))
|
||||||
|
|
Loading…
Reference in New Issue