Skip to content

Commit

Permalink
Add toggle-track action
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Apr 22, 2023
1 parent 7c6f5db commit 0c61d81
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ const (
actToggleUp
actToggleIn
actToggleOut
actToggleTrack
actDown
actUp
actPageUp
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion test/test_go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ def test_no_extra_newline_issue_3209
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'
Expand All @@ -2701,6 +2701,35 @@ def test_track
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
Expand Down

0 comments on commit 0c61d81

Please sign in to comment.