Fix track-current unset after a combined movement action
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #4649 Close #4663
authored by Junegunn Choi · committed by Junegunn Choi · parent 25b2248 · Browse files · 3 files·+57 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+57 added−20 removed
- tests:+22 added−2 removed
- other:+35 added−18 removed
Provenance
- Commit
b389616- Tree
94fcc10- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
25b2248
3 files changed+57 added−20 removed
modified:src/options.go+23 added-5 removed
290 unmodified lines291 func defaultMargin() [4]sizeSpec {292 return [4]sizeSpec{}293 }294 295-type trackOption int295+type trackOption struct {296+ enabled bool297+ index int32298+}299 297-const (298- trackDisabled trackOption = iota299- trackEnabled300- trackCurrent300+var (301+ trackDisabled = trackOption{false, minItem.Index()}302+ trackEnabled = trackOption{true, minItem.Index()}303 )304 305+func (t trackOption) Disabled() bool {306+ return !t.enabled307+}308+309+func (t trackOption) Global() bool {310+ return t.enabled && t.index == minItem.Index()311+}312+313+func (t trackOption) Current() bool {314+ return t.enabled && t.index != minItem.Index()315+}316+317+func trackCurrent(index int32) trackOption {318+ return trackOption{true, index}319+}320+321 type windowPosition int322 323 const (324 posUp windowPosition = iota3505 unmodified linesmodified:src/terminal.go+12 added-13 removed
1814 unmodified lines1815 i := t.merger.FindIndex(prevIndex)1816 if i >= 0 {1817 t.cy = i1818 t.offset = t.cy - pos1819- } else if t.track == trackCurrent {1819+ } else if t.track.Current() {1820 t.track = trackDisabled1821 t.cy = pos1822 t.offset = 01823 } else if t.cy > count {1061 unmodified lines2885 } else {2886 output += " -S"2887 }2888 }2889- switch t.track {2890- case trackEnabled:2889+ if t.track.Global() {2890 output += " +T"2892- case trackCurrent:2891+ } else if t.track.Current() {2892 output += " +t"2893 }2894 if t.multi > 0 {2895 if t.multi == maxMulti {2573 unmodified lines5469 info = true5470 case reqList:5471 t.printList()5472 currentIndex := t.currentIndex()5474- focusChanged := focusedIndex != currentIndex5475- if focusChanged && focusedIndex >= 0 && t.track == trackCurrent {5473+ if t.track.Current() && t.track.index != currentIndex {5474 t.track = trackDisabled5475 info = true5476 }5477+ focusChanged := focusedIndex != currentIndex5478 if (t.hasFocusActions || t.infoCommand != "") && focusChanged && currentIndex != t.lastFocus {5479 t.lastFocus = currentIndex5480 t.eventChan <- tui.Focus.AsEvent()5481 if t.infoCommand != "" {1066 unmodified lines6548 t.track = trackEnabled6549 }6550 req(reqInfo)6551 case actToggleTrackCurrent:6553- switch t.track {6554- case trackCurrent:6552+ if t.track.Current() {6553 t.track = trackDisabled6556- case trackDisabled:6557- t.track = trackCurrent6554+ } else if t.track.Disabled() {6555+ t.track = trackCurrent(t.currentIndex())6556 }6557 req(reqInfo)6558 case actShowHeader:6559 t.headerVisible = true39 unmodified lines6599 t.tui.ShowCursor()6600 }6601 req(reqList, reqInfo, reqPrompt, reqHeader)6602 case actTrackCurrent:6605- if t.track == trackDisabled {6606- t.track = trackCurrent6603+ // Global tracking has higher priority6604+ if !t.track.Global() {6605+ t.track = trackCurrent(t.currentIndex())6606 }6607 req(reqInfo)6608 case actUntrackCurrent:6610- if t.track == trackCurrent {6609+ if t.track.Current() {6610 t.track = trackDisabled6611 }6612 req(reqInfo)6613 case actSearch:778 unmodified linesmodified:test/test_core.rb+22 added-2 removed
1586 unmodified lines1587 end1588 end1589 1590 def test_track_action1591- tmux.send_keys "seq 1000 | #{FZF} --query 555 --bind t:track", :Enter1591+ tmux.send_keys "seq 1000 | #{FZF} --pointer x --query 555 --bind t:track,T:up+track", :Enter1592 tmux.until do |lines|1593 assert_equal 1, lines.match_count1594+ assert_includes lines, 'x 555'1595 assert_includes lines, '> 555'1596 end1597 tmux.send_keys :BSpace1598 tmux.until do |lines|1599 assert_equal 28, lines.match_count1600+ assert_includes lines, 'x 55'1601 assert_includes lines, '> 55'1602 end1603 tmux.send_keys :t1604 tmux.until do |lines|1 unmodified line1606 end1607 tmux.send_keys :BSpace1608 tmux.until do |lines|1609 assert_equal 271, lines.match_count1608- assert_includes lines, '> 55'1610+ assert_includes lines, 'x 55'1611+ assert_includes lines, '> 5'1612 end1613 1614 # Automatically disabled when the tracking item is no longer visible1615 tmux.send_keys '4'3 unmodified lines1619 end1620 tmux.send_keys :BSpace1621 tmux.until do |lines|1622 assert_equal 271, lines.match_count1623+ assert_includes lines, 'x 52'1624 assert_includes lines, '> 5'1625 end1626 tmux.send_keys :t1627 tmux.until do |lines|1628 assert_includes lines[-2], '+t'1629 end1630+1631+ # Automatically disabled when the focus has moved1632 tmux.send_keys :Up1633 tmux.until do |lines|1634+ assert_includes lines, 'x 53'1635 refute_includes lines[-2], '+t'1636 end1637+1638+ # Should work even when combined with a focus moving actions1639+ tmux.send_keys 'T'1640+ tmux.until do |lines|1641+ assert_includes lines, 'x 54'1642+ assert_includes lines[-2], '+t'1643+ end1644+1645+ tmux.send_keys 'T'1646+ tmux.until do |lines|1647+ assert_includes lines, 'x 55'1648+ assert_includes lines[-2], '+t'1649+ end1650 end1651 1652 def test_one_and_zero1653 tmux.send_keys "seq 10 | #{FZF} --bind 'zero:preview(echo no match),one:preview(echo {} is the only match)'", :Enter525 unmodified lines