Fix race condition where preview window is not properly cleared
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 8a90f26 · Browse files · 2 files·+28 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+28 added−17 removed
- tests:+7 added−1 removed
- other:+21 added−16 removed
Provenance
- Commit
e455836- Tree
f24a0a5- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
8a90f26
2 files changed+28 added−17 removed
modified:src/terminal.go+21 added-16 removed
80 unmodified lines81 }82 83 type byTimeOrder []selectedItem84 85+type previewRequest struct {86+ ok bool87+ str string88+}89+90 func (a byTimeOrder) Len() int {91 return len(a)92 }93 818 unmodified lines912 913 if t.hasPreviewWindow() {914 go func() {915 for {911- focused := ""916+ request := previewRequest{false, ""}917 t.previewBox.Wait(func(events *util.Events) {918 for req, value := range *events {919 switch req {920 case reqPreviewEnqueue:916- focused = value.(string)921+ request = value.(previewRequest)922 }923 }924 events.Clear()925 })921- if len(focused) > 0 {922- command := strings.Replace(t.preview.command, "{}", quoteEntry(focused), -1)926+ if request.ok {927+ command := strings.Replace(t.preview.command, "{}", quoteEntry(request.str), -1)928 cmd := util.ExecCommand(command)929 out, _ := cmd.CombinedOutput()930 t.reqBox.Set(reqPreviewDisplay, string(out))931+ } else {932+ t.reqBox.Set(reqPreviewDisplay, "")933 }934 }935 }()936 }5 unmodified lines942 os.Exit(code)943 }944 945 go func() {939- focused := ""946+ focused := previewRequest{false, ""}947 for {948 t.reqBox.Wait(func(events *util.Events) {949 defer events.Clear()950 t.mutex.Lock()8 unmodified lines959 t.printInfo()960 case reqList:961 t.printList()962 cnt := t.merger.Length()963+ var currentFocus previewRequest964 if cnt > 0 && cnt > t.cy {957- currentFocus := t.current()958- if currentFocus != focused {959- focused = currentFocus960- if t.isPreviewEnabled() {961- t.previewBox.Set(reqPreviewEnqueue, focused)962- }963- }965+ currentFocus = previewRequest{true, t.current()}966 } else {965- if focused != "" && t.isPreviewEnabled() {966- t.pwindow.Erase()967+ currentFocus = previewRequest{false, ""}968+ }969+ if currentFocus != focused {970+ focused = currentFocus971+ if t.isPreviewEnabled() {972+ t.previewBox.Set(reqPreviewEnqueue, focused)973 }968- focused = ""974 }975 case reqJump:976 if t.merger.Length() == 0 {977 t.jumping = jumpDisabled102 unmodified lines1080 t.previewing = !t.previewing1081 t.resizeWindows()1082 cnt := t.merger.Length()1083 if t.previewing && cnt > 0 && cnt > t.cy {1079- t.previewBox.Set(reqPreviewEnqueue, t.current())1084+ t.previewBox.Set(reqPreviewEnqueue, previewRequest{true, t.current()})1085 }1086 req(reqList, reqInfo)1087 }1088 case actToggleSort:291 unmodified linesmodified:test/test_go.rb+7 added-1 removed
1227 unmodified lines1228 assert_equal '3', readonce.chomp1229 end1230 1231 def test_preview1232- tmux.send_keys %[seq 1000 | #{FZF} --preview 'echo {{}-{}}' --bind ?:toggle-preview], :Enter1232+ tmux.send_keys %[seq 1000 | sed s/^2$// | #{FZF} --preview 'sleep 0.2; echo {{}-{}}' --bind ?:toggle-preview], :Enter1233 tmux.until { |lines| lines[1].include?(' {1-1}') }1234+ tmux.send_keys :Up1235+ tmux.until { |lines| lines[1].include?(' {-}') }1236 tmux.send_keys '555'1237 tmux.until { |lines| lines[1].include?(' {555-555}') }1238 tmux.send_keys '?'1239 tmux.until { |lines| !lines[1].include?(' {555-555}') }1240 tmux.send_keys '?'1241 tmux.until { |lines| lines[1].include?(' {555-555}') }1242+ tmux.send_keys :BSpace1243+ tmux.until { |lines| lines[-2].start_with? ' 28/1000' }1244+ tmux.send_keys 'foobar'1245+ tmux.until { |lines| !lines[1].include?('{') }1246 end1247 1248 def test_preview_hidden1249 tmux.send_keys %[seq 1000 | #{FZF} --preview 'echo {{}-{}}' --preview-window down:1:hidden --bind ?:toggle-preview], :Enter348 unmodified lines