Make sure preview command is not run before Terminal is ready

This commit is contained in:
Junegunn Choi 2024-08-11 14:48:52 +09:00
parent a2d0e8f233
commit e28f5aa45b
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -382,6 +382,7 @@ const (
reqRedrawPreviewLabel reqRedrawPreviewLabel
reqClose reqClose
reqPrintQuery reqPrintQuery
reqPreviewReady
reqPreviewEnqueue reqPreviewEnqueue
reqPreviewDisplay reqPreviewDisplay
reqPreviewRefresh reqPreviewRefresh
@ -3469,6 +3470,7 @@ func (t *Terminal) Loop() error {
go func() { go func() {
var version int64 var version int64
stop := false stop := false
t.previewBox.WaitFor(reqPreviewReady)
for { for {
var items []*Item var items []*Item
var commandTemplate string var commandTemplate string
@ -3497,6 +3499,9 @@ func (t *Terminal) Loop() error {
if stop { if stop {
break break
} }
if items == nil {
continue
}
version++ version++
// We don't display preview window if no match // We don't display preview window if no match
if items[0] != nil { if items[0] != nil {
@ -3738,6 +3743,9 @@ func (t *Terminal) Loop() error {
t.printHeader() t.printHeader()
case reqActivate: case reqActivate:
t.suppress = false t.suppress = false
if t.hasPreviewer() {
t.previewBox.Set(reqPreviewReady, nil)
}
case reqRedrawBorderLabel: case reqRedrawBorderLabel:
t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true) t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true)
case reqRedrawPreviewLabel: case reqRedrawPreviewLabel: