Skip to content
Myr

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

5 files+96 added−14 removed

modified:man/man1/fzf.1+6 added-1 removed
92 unmodified lines
93Do not sort the result94.TP95.B "--track"96Make fzf track the current selection when the result list is updated.97This can be useful when browsing logs using fzf with sorting disabled.97This can be useful when browsing logs using fzf with sorting disabled. It is98not recommended to use this option with \fB--tac\fR as the resulting behavior99can be confusing. Also, consider using \fBtrack\fR action instead of this100option.101102.RS103e.g.104 \fBgit log --oneline --graph --color=always | nl |
996 unmodified lines
1101 \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 lines
modified:src/options.go+14 added-4 removed
163 unmodified lines
164func defaultMargin() [4]sizeSpec {165 return [4]sizeSpec{}166}167168type trackOption int169170const (171 trackDisabled trackOption = iota172 trackEnabled173 trackCurrent174)175176type windowPosition int177178const (179 posUp windowPosition = iota
94 unmodified lines
274 Nth []Range275 WithNth []Range276 Delimiter Delimiter277 Sort int270 Track bool278 Track trackOption279 Tac bool280 Criteria []criterion281 Multi int282 Ansi bool
64 unmodified lines
347 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 lines
1092 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 lines
1583 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 = false
486 unmodified lines
modified:src/terminal.go+23 added-4 removed
182 unmodified lines
183 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][]*action
147 unmodified lines
339 actToggleUp340 actToggleIn341 actToggleOut342 actToggleTrack343 actTrack344 actDown345 actUp346 actPageUp347 actPageDown
574 unmodified lines
922// UpdateList updates Merger to display the list923func (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 lines
946 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 lines
1483 } 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 lines
2737 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 lines
3319 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 lines
modified:test/test_go.rb+42 added
2791 unmodified lines
2792 assert_includes lines, '> 5'2793 end2794 end27952796 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 end28162817 # 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 end28372838 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 lines
modified:CHANGELOG.md+11 added-5 removed
2 unmodified lines
340.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 improvements
1598 unmodified lines