m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-18 00:03:39 -05:00

Do not start the initial reader if 'reload*' is bound to 'start'

This commit is contained in:
Junegunn Choi
2024-06-24 17:05:53 +09:00
parent 1525768094
commit 5b52833785
5 changed files with 51 additions and 7 deletions

View File

@@ -58,6 +58,7 @@ const (
const (
EvtReadNew util.EventType = iota
EvtReadFin
EvtReadNone
EvtSearchNew
EvtSearchProgress
EvtSearchFin

View File

@@ -147,13 +147,20 @@ func Run(opts *Options) (int, error) {
executor := util.NewExecutor(opts.WithShell)
// Reader
reloadOnStart := opts.reloadOnStart()
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
var reader *Reader
if !streamingFilter {
reader = NewReader(func(data []byte) bool {
return chunkList.Push(data)
}, eventBox, executor, opts.ReadZero, opts.Filter == nil)
go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)
if reloadOnStart {
// reload or reload-sync action is bound to 'start' event, no need to start the reader
eventBox.Set(EvtReadNone, nil)
} else {
go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)
}
}
// Matcher
@@ -227,7 +234,8 @@ func Run(opts *Options) (int, error) {
}
// Synchronous search
if opts.Sync {
sync := opts.Sync && !reloadOnStart
if sync {
eventBox.Unwatch(EvtReadNew)
eventBox.WaitFor(EvtReadFin)
}
@@ -247,7 +255,7 @@ func Run(opts *Options) (int, error) {
if heightUnknown {
maxFit, padHeight = terminal.MaxFitAndPad()
}
deferred := opts.Select1 || opts.Exit0 || opts.Sync
deferred := opts.Select1 || opts.Exit0 || sync
go terminal.Loop()
if !deferred && !heightUnknown {
// Start right away
@@ -314,6 +322,9 @@ func Run(opts *Options) (int, error) {
err = quitSignal.err
stop = true
return
case EvtReadNone:
reading = false
terminal.UpdateCount(0, false, nil)
case EvtReadNew, EvtReadFin:
if evt == EvtReadFin && nextCommand != nil {
restart(*nextCommand, nextEnviron)

View File

@@ -2945,3 +2945,18 @@ func ParseOptions(useDefaults bool, args []string) (*Options, error) {
return opts, nil
}
func (opts *Options) reloadOnStart() bool {
// Not compatible with --filter
if opts.Filter != nil {
return false
}
if actions, prs := opts.Keymap[tui.Start.AsEvent()]; prs {
for _, action := range actions {
if action.t == actReload || action.t == actReloadSync {
return true
}
}
}
return false
}