mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-18 00:03:39 -05:00
Fix race condition where preview window is not properly cleared
This commit is contained in:
@@ -82,6 +82,11 @@ type selectedItem struct {
|
||||
|
||||
type byTimeOrder []selectedItem
|
||||
|
||||
type previewRequest struct {
|
||||
ok bool
|
||||
str string
|
||||
}
|
||||
|
||||
func (a byTimeOrder) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
@@ -908,21 +913,23 @@ func (t *Terminal) Loop() {
|
||||
if t.hasPreviewWindow() {
|
||||
go func() {
|
||||
for {
|
||||
focused := ""
|
||||
request := previewRequest{false, ""}
|
||||
t.previewBox.Wait(func(events *util.Events) {
|
||||
for req, value := range *events {
|
||||
switch req {
|
||||
case reqPreviewEnqueue:
|
||||
focused = value.(string)
|
||||
request = value.(previewRequest)
|
||||
}
|
||||
}
|
||||
events.Clear()
|
||||
})
|
||||
if len(focused) > 0 {
|
||||
command := strings.Replace(t.preview.command, "{}", quoteEntry(focused), -1)
|
||||
if request.ok {
|
||||
command := strings.Replace(t.preview.command, "{}", quoteEntry(request.str), -1)
|
||||
cmd := util.ExecCommand(command)
|
||||
out, _ := cmd.CombinedOutput()
|
||||
t.reqBox.Set(reqPreviewDisplay, string(out))
|
||||
} else {
|
||||
t.reqBox.Set(reqPreviewDisplay, "")
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -936,7 +943,7 @@ func (t *Terminal) Loop() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
focused := ""
|
||||
focused := previewRequest{false, ""}
|
||||
for {
|
||||
t.reqBox.Wait(func(events *util.Events) {
|
||||
defer events.Clear()
|
||||
@@ -953,19 +960,17 @@ func (t *Terminal) Loop() {
|
||||
case reqList:
|
||||
t.printList()
|
||||
cnt := t.merger.Length()
|
||||
var currentFocus previewRequest
|
||||
if cnt > 0 && cnt > t.cy {
|
||||
currentFocus := t.current()
|
||||
if currentFocus != focused {
|
||||
focused = currentFocus
|
||||
if t.isPreviewEnabled() {
|
||||
t.previewBox.Set(reqPreviewEnqueue, focused)
|
||||
}
|
||||
}
|
||||
currentFocus = previewRequest{true, t.current()}
|
||||
} else {
|
||||
if focused != "" && t.isPreviewEnabled() {
|
||||
t.pwindow.Erase()
|
||||
currentFocus = previewRequest{false, ""}
|
||||
}
|
||||
if currentFocus != focused {
|
||||
focused = currentFocus
|
||||
if t.isPreviewEnabled() {
|
||||
t.previewBox.Set(reqPreviewEnqueue, focused)
|
||||
}
|
||||
focused = ""
|
||||
}
|
||||
case reqJump:
|
||||
if t.merger.Length() == 0 {
|
||||
@@ -1076,7 +1081,7 @@ func (t *Terminal) Loop() {
|
||||
t.resizeWindows()
|
||||
cnt := t.merger.Length()
|
||||
if t.previewing && cnt > 0 && cnt > t.cy {
|
||||
t.previewBox.Set(reqPreviewEnqueue, t.current())
|
||||
t.previewBox.Set(reqPreviewEnqueue, previewRequest{true, t.current()})
|
||||
}
|
||||
req(reqList, reqInfo)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user