parent
bc3983181d
commit
a0a3c349c9
@ -101,6 +101,7 @@ type Terminal struct {
|
|||||||
printer func(string)
|
printer func(string)
|
||||||
merger *Merger
|
merger *Merger
|
||||||
selected map[int32]selectedItem
|
selected map[int32]selectedItem
|
||||||
|
version int64
|
||||||
reqBox *util.EventBox
|
reqBox *util.EventBox
|
||||||
preview previewOpts
|
preview previewOpts
|
||||||
previewer previewer
|
previewer previewer
|
||||||
@ -1257,6 +1258,24 @@ func (t *Terminal) truncateQuery() {
|
|||||||
t.cx = util.Constrain(t.cx, 0, len(t.input))
|
t.cx = util.Constrain(t.cx, 0, len(t.input))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) selectItem(item *Item) {
|
||||||
|
t.selected[item.Index()] = selectedItem{time.Now(), item}
|
||||||
|
t.version++
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) deselectItem(item *Item) {
|
||||||
|
delete(t.selected, item.Index())
|
||||||
|
t.version++
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) toggleItem(item *Item) {
|
||||||
|
if _, found := t.selected[item.Index()]; !found {
|
||||||
|
t.selectItem(item)
|
||||||
|
} else {
|
||||||
|
t.deselectItem(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Loop is called to start Terminal I/O
|
// Loop is called to start Terminal I/O
|
||||||
func (t *Terminal) Loop() {
|
func (t *Terminal) Loop() {
|
||||||
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
||||||
@ -1359,6 +1378,7 @@ func (t *Terminal) Loop() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var focused *Item
|
var focused *Item
|
||||||
|
var version int64
|
||||||
for {
|
for {
|
||||||
t.reqBox.Wait(func(events *util.Events) {
|
t.reqBox.Wait(func(events *util.Events) {
|
||||||
defer events.Clear()
|
defer events.Clear()
|
||||||
@ -1375,7 +1395,8 @@ func (t *Terminal) Loop() {
|
|||||||
case reqList:
|
case reqList:
|
||||||
t.printList()
|
t.printList()
|
||||||
currentFocus := t.currentItem()
|
currentFocus := t.currentItem()
|
||||||
if currentFocus != focused {
|
if currentFocus != focused || version != t.version {
|
||||||
|
version = t.version
|
||||||
focused = currentFocus
|
focused = currentFocus
|
||||||
if t.isPreviewEnabled() {
|
if t.isPreviewEnabled() {
|
||||||
_, list := t.buildPlusList(t.preview.command, false)
|
_, list := t.buildPlusList(t.preview.command, false)
|
||||||
@ -1441,22 +1462,9 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectItem := func(item *Item) bool {
|
|
||||||
if _, found := t.selected[item.Index()]; !found {
|
|
||||||
t.selected[item.Index()] = selectedItem{time.Now(), item}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
toggleY := func(y int) {
|
|
||||||
item := t.merger.Get(y).item
|
|
||||||
if !selectItem(item) {
|
|
||||||
delete(t.selected, item.Index())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toggle := func() {
|
toggle := func() {
|
||||||
if t.cy < t.merger.Length() {
|
if t.cy < t.merger.Length() {
|
||||||
toggleY(t.cy)
|
t.toggleItem(t.merger.Get(t.cy).item)
|
||||||
req(reqInfo)
|
req(reqInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1570,16 +1578,14 @@ func (t *Terminal) Loop() {
|
|||||||
case actSelectAll:
|
case actSelectAll:
|
||||||
if t.multi {
|
if t.multi {
|
||||||
for i := 0; i < t.merger.Length(); i++ {
|
for i := 0; i < t.merger.Length(); i++ {
|
||||||
item := t.merger.Get(i).item
|
t.selectItem(t.merger.Get(i).item)
|
||||||
selectItem(item)
|
|
||||||
}
|
}
|
||||||
req(reqList, reqInfo)
|
req(reqList, reqInfo)
|
||||||
}
|
}
|
||||||
case actDeselectAll:
|
case actDeselectAll:
|
||||||
if t.multi {
|
if t.multi {
|
||||||
for i := 0; i < t.merger.Length(); i++ {
|
for i := 0; i < t.merger.Length(); i++ {
|
||||||
item := t.merger.Get(i)
|
t.deselectItem(t.merger.Get(i).item)
|
||||||
delete(t.selected, item.Index())
|
|
||||||
}
|
}
|
||||||
req(reqList, reqInfo)
|
req(reqList, reqInfo)
|
||||||
}
|
}
|
||||||
@ -1591,7 +1597,7 @@ func (t *Terminal) Loop() {
|
|||||||
case actToggleAll:
|
case actToggleAll:
|
||||||
if t.multi {
|
if t.multi {
|
||||||
for i := 0; i < t.merger.Length(); i++ {
|
for i := 0; i < t.merger.Length(); i++ {
|
||||||
toggleY(i)
|
t.toggleItem(t.merger.Get(i).item)
|
||||||
}
|
}
|
||||||
req(reqList, reqInfo)
|
req(reqList, reqInfo)
|
||||||
}
|
}
|
||||||
|
@ -1274,6 +1274,16 @@ class TestGoFZF < TestBase
|
|||||||
tmux.until { |lines| lines[-3] == '> 11' }
|
tmux.until { |lines| lines[-3] == '> 11' }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_preview_update_on_select
|
||||||
|
tmux.send_keys(%(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),
|
||||||
|
:Enter)
|
||||||
|
tmux.until { |lines| lines.item_count == 10 }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| lines.any? { |line| line.include? '1 2 3 4 5' } }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| !lines.any? { |line| line.include? '1 2 3 4 5' } }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TestShell
|
module TestShell
|
||||||
|
Loading…
x
Reference in New Issue
Block a user