Fix reload and reload-sync behaviors

https://github.com/junegunn/fzf/discussions/3696#discussioncomment-8915593
This commit is contained in:
Junegunn Choi
2024-03-27 17:25:56 +09:00
parent db6db49ed6
commit 008fb9d258
3 changed files with 91 additions and 6 deletions

View File

@@ -245,11 +245,8 @@ func Run(opts *Options, version string, revision string) {
delay := true
ticks++
input := func() []rune {
reloaded := snapshotRevision != inputRevision
paused, input := terminal.Input()
if reloaded && paused {
query = []rune{}
} else if !paused {
if !paused {
query = input
}
return query
@@ -278,6 +275,9 @@ func Run(opts *Options, version string, revision string) {
useSnapshot = false
}
if !useSnapshot {
if snapshotRevision != inputRevision {
query = []rune{}
}
snapshot, count = chunkList.Snapshot()
snapshotRevision = inputRevision
}
@@ -319,10 +319,13 @@ func Run(opts *Options, version string, revision string) {
break
}
if !useSnapshot {
newSnapshot, _ := chunkList.Snapshot()
newSnapshot, newCount := chunkList.Snapshot()
// We want to avoid showing empty list when reload is triggered
// and the query string is changed at the same time i.e. command != nil && changed
if command == nil || len(newSnapshot) > 0 {
if command == nil || newCount > 0 {
if snapshotRevision != inputRevision {
query = []rune{}
}
snapshot = newSnapshot
snapshotRevision = inputRevision
}