From 0c61d8171374337bdc37ac217b09c0b30d1b37ee Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 22 Apr 2023 15:48:51 +0900 Subject: [PATCH] Add toggle-track action --- CHANGELOG.md | 11 +++++++++++ src/terminal.go | 7 +++++++ test/test_go.rb | 31 ++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec087b0..838ce17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ CHANGELOG 0.39.1 ------ +- Added `toggle-track` action. Temporarily enabling tracking is useful when + you want to see the surrounding items by deleting the query string. + ```sh + export FZF_CTRL_R_OPTS=" + --preview 'echo {}' --preview-window up:3:hidden:wrap + --bind 'ctrl-/:toggle-preview' + --bind 'ctrl-t:toggle-track' + --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' + --color header:italic + --header 'Press CTRL-Y to copy command into clipboard'" + ``` - Fixed `--track` behavior when used with `--tac` - However, using `--track` with `--tac` is not recommended. The resulting behavior can be very confusing. diff --git a/src/terminal.go b/src/terminal.go index cbbde9c..20a15d9 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -337,6 +337,7 @@ const ( actToggleUp actToggleIn actToggleOut + actToggleTrack actDown actUp actPageUp @@ -1464,6 +1465,9 @@ func (t *Terminal) printInfo() { output += " -S" } } + if t.track { + output += " +T" + } if t.multi > 0 { if t.multi == maxMulti { output += fmt.Sprintf(" (%d)", len(t.selected)) @@ -3274,6 +3278,9 @@ func (t *Terminal) Loop() { t.paused = !t.paused changed = !t.paused req(reqPrompt) + case actToggleTrack: + t.track = !t.track + req(reqInfo) case actEnableSearch: t.paused = false changed = true diff --git a/test/test_go.rb b/test/test_go.rb index 9285a07..d1fa2c3 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -2681,7 +2681,7 @@ class TestGoFZF < TestBase end def test_track - tmux.send_keys "seq 1000 | #{FZF} --query 555 --track", :Enter + tmux.send_keys "seq 1000 | #{FZF} --query 555 --track --bind t:toggle-track", :Enter tmux.until do |lines| assert_equal 1, lines.match_count assert_includes lines, '> 555' @@ -2701,6 +2701,35 @@ class TestGoFZF < TestBase assert_equal 1000, lines.match_count assert_equal '> 555', lines[index] end + tmux.send_keys '555' + tmux.until do |lines| + assert_equal 1, lines.match_count + assert_includes lines, '> 555' + assert_includes lines[-2], '+T' + end + tmux.send_keys 't' + tmux.until do |lines| + refute_includes lines[-2], '+T' + end + tmux.send_keys :BSpace + tmux.until do |lines| + assert_equal 28, lines.match_count + assert_includes lines, '> 55' + end + tmux.send_keys :BSpace + tmux.until do |lines| + assert_equal 271, lines.match_count + assert_includes lines, '> 5' + end + tmux.send_keys 't' + tmux.until do |lines| + assert_includes lines[-2], '+T' + end + tmux.send_keys :BSpace + tmux.until do |lines| + assert_equal 1000, lines.match_count + assert_includes lines, '> 5' + end end def test_one