From aa2f2087f006029959b7eef4021a97dae0d7aa9a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 28 Feb 2026 13:27:31 +0900 Subject: [PATCH] Fix multi-line scrolling after change-with-nth Clear numLinesCache when with-nth changes so the constrain/scrolling logic recalculates item heights instead of using stale cached values. --- src/terminal.go | 1 + test/test_core.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/terminal.go b/src/terminal.go index a87064e4..fabb5b43 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -6397,6 +6397,7 @@ func (t *Terminal) Loop() error { t.withNthExpr = withNthExpr t.filterSelection = true changed = true + t.clearNumLinesCache() t.forceRerenderList() } }) diff --git a/test/test_core.rb b/test/test_core.rb index a9f7418f..9eb30f43 100644 --- a/test/test_core.rb +++ b/test/test_core.rb @@ -1884,6 +1884,43 @@ class TestCore < TestInteractive end end + def test_change_with_nth_multiline + # Each item has 3 lines: "N-a\nN-b\nN-c" + # --with-nth 1 shows 1 line per item, --with-nth 1..3 shows 3 lines per item + tmux.send_keys %(seq 20 | xargs -I{} printf '{}-a\\n{}-b\\n{}-c\\0' | #{FZF} --read0 --delimiter "\n" --with-nth 1 --bind 'space:change-with-nth(1..3|1)' --no-sort), :Enter + tmux.until do |lines| + assert_equal 20, lines.item_count + assert lines.any_include?('1-a') + refute lines.any_include?('1-b') + end + # Expand to 3 lines per item + tmux.send_keys :Space + tmux.until do |lines| + assert lines.any_include?('1-a') + assert lines.any_include?('1-b') + assert lines.any_include?('1-c') + end + # Scroll down a few items + 5.times { tmux.send_keys :Down } + tmux.until do |lines| + assert lines.any_include?('6-a') + assert lines.any_include?('6-b') + assert lines.any_include?('6-c') + end + # Collapse back to 1 line per item + tmux.send_keys :Space + tmux.until do |lines| + assert lines.any_include?('6-a') + refute lines.any_include?('6-b') + end + # Scroll down more after collapse + 5.times { tmux.send_keys :Down } + tmux.until do |lines| + assert lines.any_include?('11-a') + refute lines.any_include?('11-b') + end + end + def test_env_vars def env_vars return {} unless File.exist?(tempname)