Skip to content
Myr

Fix reload and reload-sync behaviors

Before adoption: this commit came in with the history the project adopted, so no landing records it.

https://github.com/junegunn/fzf/discussions/3696#discussioncomment-8915593

authored by Junegunn Choi · committed by Junegunn Choi · parent db6db49 · Browse files · 3 files+91 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • https: //github.com/junegunn/fzf/discussions/3696#discussioncomment-8915593

Diff stats

3 files+91 added−6 removed

  • tests:+78 added−0 removed
  • other:+13 added−6 removed

3 files+91 added−6 removed

modified:src/core.go+9 added-6 removed
243 unmodified lines
244 for {245 delay := true246 ticks++247 input := func() []rune {248 reloaded := snapshotRevision != inputRevision248 paused, input := terminal.Input()250 if reloaded && paused {251 query = []rune{}252 } else if !paused {249 if !paused {250 query = input251 }252 return query253 }
20 unmodified lines
274 if useSnapshot && evt == EvtReadFin {275 useSnapshot = false276 }277 if !useSnapshot {278 if snapshotRevision != inputRevision {279 query = []rune{}280 }281 snapshot, count = chunkList.Snapshot()282 snapshotRevision = inputRevision283 }284 total = count
33 unmodified lines
318 if !changed {319 break320 }321 if !useSnapshot {322 newSnapshot, _ := chunkList.Snapshot()322 newSnapshot, newCount := chunkList.Snapshot()323 // We want to avoid showing empty list when reload is triggered324 // and the query string is changed at the same time i.e. command != nil && changed325 if command == nil || len(newSnapshot) > 0 {325 if command == nil || newCount > 0 {326 if snapshotRevision != inputRevision {327 query = []rune{}328 }329 snapshot = newSnapshot330 snapshotRevision = inputRevision331 }332 }
54 unmodified lines
modified:test/test_go.rb+78 added
2461 unmodified lines
2462 # After 1 second2463 tmux.until { |lines| assert_equal 10, lines.match_count }2464 end24652466 def test_reload_disabled_case12467 tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)'", :Enter2468 tmux.until do |lines|2469 assert_equal 100, lines.item_count2470 assert_equal 1, lines.match_count2471 end2472 tmux.send_keys :Space2473 tmux.until { |lines| assert_equal 1, lines.match_count }2474 tmux.send_keys :BSpace2475 tmux.until { |lines| assert_equal 0, lines.match_count }2476 tmux.until { |lines| assert_equal 1000, lines.match_count }2477 end24782479 def test_reload_disabled_case22480 tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)'", :Enter2481 tmux.until do |lines|2482 assert_equal 100, lines.item_count2483 assert_equal 1, lines.match_count2484 end2485 tmux.send_keys :Space2486 tmux.until { |lines| assert_equal 1, lines.match_count }2487 tmux.send_keys :BSpace2488 tmux.until { |lines| assert_equal 1, lines.match_count }2489 tmux.until { |lines| assert_equal 1000, lines.match_count }2490 end24912492 def test_reload_disabled_case32493 tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)+backward-delete-char'", :Enter2494 tmux.until do |lines|2495 assert_equal 100, lines.item_count2496 assert_equal 1, lines.match_count2497 end2498 tmux.send_keys :Space2499 tmux.until { |lines| assert_equal 1, lines.match_count }2500 tmux.send_keys :BSpace2501 tmux.until { |lines| assert_equal 0, lines.match_count }2502 tmux.until { |lines| assert_equal 1000, lines.match_count }2503 end25042505 def test_reload_disabled_case42506 tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)+backward-delete-char'", :Enter2507 tmux.until do |lines|2508 assert_equal 100, lines.item_count2509 assert_equal 1, lines.match_count2510 end2511 tmux.send_keys :Space2512 tmux.until { |lines| assert_equal 1, lines.match_count }2513 tmux.send_keys :BSpace2514 tmux.until { |lines| assert_equal 1, lines.match_count }2515 tmux.until { |lines| assert_equal 1000, lines.match_count }2516 end25172518 def test_reload_disabled_case52519 tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(echo xx; sleep 2; seq 1000)'", :Enter2520 tmux.until do |lines|2521 assert_equal 100, lines.item_count2522 assert_equal 1, lines.match_count2523 end2524 tmux.send_keys :Space2525 tmux.until do |lines|2526 assert_equal 1, lines.item_count2527 assert_equal 1, lines.match_count2528 end2529 tmux.send_keys :BSpace2530 tmux.until { |lines| assert_equal 1001, lines.match_count }2531 end25322533 def test_reload_disabled_case62534 tmux.send_keys "seq 1000 | #{FZF} --disabled --bind 'change:reload:sleep 0.5; seq {q}'", :Enter2535 tmux.until { |lines| assert_equal 1000, lines.match_count }2536 tmux.send_keys '9'2537 tmux.until { |lines| assert_equal 9, lines.match_count }2538 tmux.send_keys '9'2539 tmux.until { |lines| assert_equal 99, lines.match_count }25402541 # TODO: How do we verify if an intermedite empty list is not shown?2542 end25432544 def test_scroll_off2545 tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter2546 tmux.until { |lines| assert_equal 1000, lines.item_count }2547 height = tmux.until { |lines| lines }.first.to_i
1160 unmodified lines
modified:CHANGELOG.md+4 added
1CHANGELOG2=========340.48.25------6- Bug fixes780.48.19------10- 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 script11 ```sh
1945 unmodified lines