Add 'track' action
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 6be855b · Browse files · 5 files·+96 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+96 added−14 removed
- tests:+42 added−0 removed
- other:+54 added−14 removed
Provenance
- Commit
65dd2bb- Tree
8f5744d- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
6be855b
5 files changed+96 added−14 removed
modified:man/man1/fzf.1+6 added-1 removed
92 unmodified lines93 Do not sort the result94 .TP95 .B "--track"96 Make fzf track the current selection when the result list is updated.97-This can be useful when browsing logs using fzf with sorting disabled.97+This can be useful when browsing logs using fzf with sorting disabled. It is98+not recommended to use this option with \fB--tac\fR as the resulting behavior99+can be confusing. Also, consider using \fBtrack\fR action instead of this100+option.101 102 .RS103 e.g.104 \fBgit log --oneline --graph --color=always | nl |996 unmodified lines1101 \fBtoggle-preview\fR1102 \fBtoggle-preview-wrap\fR1103 \fBtoggle-search\fR (toggle search functionality)1104 \fBtoggle-sort\fR1105+ \fBtoggle-track\fR1106 \fBtoggle+up\fR \fIbtab (shift-tab)\fR1107+ \fBtrack\fR (track the current item; automatically disabled if focus changes)1108 \fBtransform-border-label(...)\fR (transform border label using an external command)1109 \fBtransform-header(...)\fR (transform header using an external command)1110 \fBtransform-preview-label(...)\fR (transform preview label using an external command)1111 \fBtransform-prompt(...)\fR (transform prompt string using an external command)159 unmodified linesmodified:src/options.go+14 added-4 removed
163 unmodified lines164 func defaultMargin() [4]sizeSpec {165 return [4]sizeSpec{}166 }167 168+type trackOption int169+170+const (171+ trackDisabled trackOption = iota172+ trackEnabled173+ trackCurrent174+)175+176 type windowPosition int177 178 const (179 posUp windowPosition = iota94 unmodified lines274 Nth []Range275 WithNth []Range276 Delimiter Delimiter277 Sort int270- Track bool278+ Track trackOption279 Tac bool280 Criteria []criterion281 Multi int282 Ansi bool64 unmodified lines347 Nth: make([]Range, 0),348 WithNth: make([]Range, 0),349 Delimiter: Delimiter{},350 Sort: 1000,343- Track: false,351+ Track: trackDisabled,352 Tac: false,353 Criteria: []criterion{byScore, byLength},354 Multi: 0,355 Ansi: false,736 unmodified lines1092 case "toggle-search":1093 appendAction(actToggleSearch)1094 case "toggle-track":1095 appendAction(actToggleTrack)1096+ case "track":1097+ appendAction(actTrack)1098 case "select":1099 appendAction(actSelect)1100 case "select-all":1101 appendAction(actSelectAll)481 unmodified lines1583 opts.Sort = optionalNumeric(allArgs, &i, 1)1584 case "+s", "--no-sort":1585 opts.Sort = 01586 case "--track":1577- opts.Track = true1587+ opts.Track = trackEnabled1588 case "--no-track":1579- opts.Track = false1589+ opts.Track = trackDisabled1590 case "--tac":1591 opts.Tac = true1592 case "--no-tac":1593 opts.Tac = false486 unmodified linesmodified:src/terminal.go+23 added-4 removed
182 unmodified lines183 input []rune184 multi int185 sort bool186 toggleSort bool187- track bool187+ track trackOption188 delimiter Delimiter189 expect map[tui.Event]string190 keymap map[tui.Event][]*action191 keymapOrg map[tui.Event][]*action147 unmodified lines339 actToggleUp340 actToggleIn341 actToggleOut342 actToggleTrack343+ actTrack344 actDown345 actUp346 actPageUp347 actPageDown574 unmodified lines922 // UpdateList updates Merger to display the list923 func (t *Terminal) UpdateList(merger *Merger, reset bool) {924 t.mutex.Lock()925 var prevIndex int32 = -1925- if !reset && t.track {926+ if !reset && t.track != trackDisabled {927 if t.merger.Length() > 0 {928 prevIndex = t.merger.Get(t.cy).item.Index()929 } else if merger.Length() > 0 {930 prevIndex = merger.First().item.Index()15 unmodified lines946 i := t.merger.FindIndex(prevIndex)947 if i >= 0 {948 t.cy = i949 t.offset = t.cy - pos950+ } else if t.track == trackCurrent {951+ t.track = trackDisabled952+ t.cy = pos953+ t.offset = 0954 } else if t.cy > count {955 // Try to keep the vertical position when the list shrinks956 t.cy = count - util.Min(count, t.maxItems()) + pos957 }525 unmodified lines1483 } else {1484 output += " -S"1485 }1486 }1482- if t.track {1487+ if t.track != trackDisabled {1488 output += " +T"1489 }1490 if t.multi > 0 {1491 if t.multi == maxMulti {1245 unmodified lines2737 if currentItem != nil {2738 currentIndex = currentItem.Index()2739 }2740 focusChanged := focusedIndex != currentIndex2741+ if focusChanged && t.track == trackCurrent {2742+ t.track = trackDisabled2743+ t.printInfo()2744+ }2745 if onFocus != nil && focusChanged {2746 t.serverChan <- onFocus2747 }2748 if focusChanged || version != t.version {570 unmodified lines3319 t.paused = !t.paused3320 changed = !t.paused3321 req(reqPrompt)3322 case actToggleTrack:3314- t.track = !t.track3323+ switch t.track {3324+ case trackEnabled:3325+ t.track = trackDisabled3326+ case trackDisabled:3327+ t.track = trackEnabled3328+ }3329 req(reqInfo)3330+ case actTrack:3331+ if t.track == trackDisabled {3332+ t.track = trackCurrent3333+ }3334+ req(reqInfo)3335 case actEnableSearch:3336 t.paused = false3337 changed = true3338 req(reqPrompt)348 unmodified linesmodified:test/test_go.rb+42 added
2791 unmodified lines2792 assert_includes lines, '> 5'2793 end2794 end2795 2796+ def test_track_action2797+ tmux.send_keys "seq 1000 | #{FZF} --query 555 --bind t:track", :Enter2798+ tmux.until do |lines|2799+ assert_equal 1, lines.match_count2800+ assert_includes lines, '> 555'2801+ end2802+ tmux.send_keys :BSpace2803+ tmux.until do |lines|2804+ assert_equal 28, lines.match_count2805+ assert_includes lines, '> 55'2806+ end2807+ tmux.send_keys :t2808+ tmux.until do |lines|2809+ assert_includes lines[-2], '+T'2810+ end2811+ tmux.send_keys :BSpace2812+ tmux.until do |lines|2813+ assert_equal 271, lines.match_count2814+ assert_includes lines, '> 55'2815+ end2816+2817+ # Automatically disabled when the tracking item is no longer visible2818+ tmux.send_keys '4'2819+ tmux.until do |lines|2820+ assert_equal 28, lines.match_count2821+ refute_includes lines[-2], '+T'2822+ end2823+ tmux.send_keys :BSpace2824+ tmux.until do |lines|2825+ assert_equal 271, lines.match_count2826+ assert_includes lines, '> 5'2827+ end2828+ tmux.send_keys :t2829+ tmux.until do |lines|2830+ assert_includes lines[-2], '+T'2831+ end2832+ tmux.send_keys :Up2833+ tmux.until do |lines|2834+ refute_includes lines[-2], '+T'2835+ end2836+ end2837+2838 def test_one2839 tmux.send_keys "seq 10 | #{FZF} --bind 'one:preview:echo {} is the only match'", :Enter2840 tmux.send_keys '1'2841 tmux.until do |lines|501 unmodified linesmodified:CHANGELOG.md+11 added-5 removed
2 unmodified lines3 4 0.40.05 ------6 - New actions7- - Added `change-header(...)`8- - Added `transform-header(...)`9- - Added `toggle-track` action. Temporarily enabling tracking is useful when10- you want to see the surrounding items by deleting the query string.7+ - Added `track` action which makes fzf track the current item when the8+ search result is updated. If the user manually moves the cursor, or the9+ item is not in the updated search result, tracking is automatically10+ disabled. Tracking is useful when you want to see the surrounding items11+ by deleting the query string.12 ```sh13+ # Narrow down the list with a query, point to a command,14+ # and hit CTRL-T to see its surrounding commands.15 export FZF_CTRL_R_OPTS="16 --preview 'echo {}' --preview-window up:3:hidden:wrap17 --bind 'ctrl-/:toggle-preview'15- --bind 'ctrl-t:toggle-track'18+ --bind 'ctrl-t:track+clear-query'19 --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'20 --color header:italic21 --header 'Press CTRL-Y to copy command into clipboard'"22 ```23+ - Added `change-header(...)`24+ - Added `transform-header(...)`25+ - Added `toggle-track` action26 - Fixed `--track` behavior when used with `--tac`27 - However, using `--track` with `--tac` is not recommended. The resulting28 behavior can be very confusing.29 - Bug fixes and improvements1598 unmodified lines