summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-03-27 17:25:56 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-03-27 17:25:56 +0900
commit008fb9d258e47815a7c36f462bfb0a7fe08ec44f (patch)
treec73bb7df813f6dab765dd660ffbb5d7a31660641
parentdb6db49ed642caf9cbe716f80d4fa40052118068 (diff)
Fix reload and reload-sync behaviors
https://github.com/junegunn/fzf/discussions/3696#discussioncomment-8915593
-rw-r--r--CHANGELOG.md4
-rw-r--r--src/core.go15
-rwxr-xr-xtest/test_go.rb78
3 files changed, 91 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc312d79..c239efab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
CHANGELOG
=========
+0.48.2
+------
+- Bug fixes
+
0.48.1
------
- CTRL-T and ALT-C bindings can be disabled by setting `FZF_CTRL_T_COMMAND` and `FZF_ALT_C_COMMAND` to empty strings respectively when sourcing the script
diff --git a/src/core.go b/src/core.go
index 3abda89c..f6c5a50d 100644
--- a/src/core.go
+++ b/src/core.go
@@ -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
}
diff --git a/test/test_go.rb b/test/test_go.rb
index 97061de0..533a3b23 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -2463,6 +2463,84 @@ class TestGoFZF < TestBase
tmux.until { |lines| assert_equal 10, lines.match_count }
end
+ def test_reload_disabled_case1
+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)'", :Enter
+ tmux.until do |lines|
+ assert_equal 100, lines.item_count
+ assert_equal 1, lines.match_count
+ end
+ tmux.send_keys :Space
+ tmux.until { |lines| assert_equal 1, lines.match_count }
+ tmux.send_keys :BSpace
+ tmux.until { |lines| assert_equal 0, lines.match_count }
+ tmux.until { |lines| assert_equal 1000, lines.match_count }
+ end
+
+ def test_reload_disabled_case2
+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)'", :Enter
+ tmux.until do |lines|
+ assert_equal 100, lines.item_count
+ assert_equal 1, lines.match_count
+ end
+ tmux.send_keys :Space
+ tmux.until { |lines| assert_equal 1, lines.match_count }
+ tmux.send_keys :BSpace
+ tmux.until { |lines| assert_equal 1, lines.match_count }
+ tmux.until { |lines| assert_equal 1000, lines.match_count }
+ end
+
+ def test_reload_disabled_case3
+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)+backward-delete-char'", :Enter
+ tmux.until do |lines|
+ assert_equal 100, lines.item_count
+ assert_equal 1, lines.match_count
+ end
+ tmux.send_keys :Space
+ tmux.until { |lines| assert_equal 1, lines.match_count }
+ tmux.send_keys :BSpace
+ tmux.until { |lines| assert_equal 0, lines.match_count }
+ tmux.until { |lines| assert_equal 1000, lines.match_count }
+ end
+
+ def test_reload_disabled_case4
+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)+backward-delete-char'", :Enter
+ tmux.until do |lines|
+ assert_equal 100, lines.item_count
+ assert_equal 1, lines.match_count
+ end
+ tmux.send_keys :Space
+ tmux.until { |lines| assert_equal 1, lines.match_count }
+ tmux.send_keys :BSpace
+ tmux.until { |lines| assert_equal 1, lines.match_count }
+ tmux.until { |lines| assert_equal 1000, lines.match_count }
+ end
+
+ def test_reload_disabled_case5
+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(echo xx; sleep 2; seq 1000)'", :Enter
+ tmux.until do |lines|
+ assert_equal 100, lines.item_count
+ assert_equal 1, lines.match_count
+ end
+ tmux.send_keys :Space
+ tmux.until do |lines|
+ assert_equal 1, lines.item_count
+ assert_equal 1, lines.match_count
+ end
+ tmux.send_keys :BSpace
+ tmux.until { |lines| assert_equal 1001, lines.match_count }
+ end
+
+ def test_reload_disabled_case6
+ tmux.send_keys "seq 1000 | #{FZF} --disabled --bind 'change:reload:sleep 0.5; seq {q}'", :Enter
+ tmux.until { |lines| assert_equal 1000, lines.match_count }
+ tmux.send_keys '9'
+ tmux.until { |lines| assert_equal 9, lines.match_count }
+ tmux.send_keys '9'
+ tmux.until { |lines| assert_equal 99, lines.match_count }
+
+ # TODO: How do we verify if an intermedite empty list is not shown?
+ end
+
def test_scroll_off
tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter
tmux.until { |lines| assert_equal 1000, lines.item_count }