Skip to content
Myr

Add actions for --bind: select-all / deselect-all / toggle-all

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #257

authored by Junegunn Choi · committed by Junegunn Choi · parent 1b9b1d1 · Browse files · 3 files+75 added−12 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+75 added−12 removed

  • tests:+23 added−0 removed
  • other:+52 added−12 removed

3 files+75 added−12 removed

modified:src/options.go+6 added
406 unmodified lines
407 case "toggle-down":408 keymap[key] = actToggleDown409 case "toggle-up":410 keymap[key] = actToggleUp411 case "toggle-all":412 keymap[key] = actToggleAll413 case "select-all":414 keymap[key] = actSelectAll415 case "deselect-all":416 keymap[key] = actDeselectAll417 case "toggle":418 keymap[key] = actToggle419 case "down":420 keymap[key] = actDown
186 unmodified lines
modified:src/terminal.go+46 added-12 removed
103 unmodified lines
104 actUnixLineDiscard105 actUnixWordRubout106 actYank107 actBackwardKillWord108 actSelectAll109 actDeselectAll110 actToggle111 actToggleAll112 actToggleDown113 actToggleUp114 actDown115 actUp
547 unmodified lines
663 looping = false664 }665 }666 }664 toggle := func() {665 if t.cy < t.merger.Length() {666 item := t.merger.Get(t.cy)667 if _, found := t.selected[item.index]; !found {668 var strptr *string669 if item.origText != nil {670 strptr = item.origText667 selectItem := func(item *Item) bool {668 if _, found := t.selected[item.index]; !found {669 var strptr *string670 if item.origText != nil {671 strptr = item.origText671 } else {672 strptr = item.text673 }674 t.selected[item.index] = selectedItem{time.Now(), strptr}672 } else {676 delete(t.selected, item.index)673 strptr = item.text674 }675 t.selected[item.index] = selectedItem{time.Now(), strptr}676 return true677 }678 return false679 }680 toggleY := func(y int) {681 item := t.merger.Get(y)682 if !selectItem(item) {683 delete(t.selected, item.index)684 }685 }686 toggle := func() {687 if t.cy < t.merger.Length() {688 toggleY(t.cy)689 req(reqInfo)690 }691 }692 for _, key := range t.expect {
42 unmodified lines
735 if t.cx > 0 {736 t.input = append(t.input[:t.cx-1], t.input[t.cx:]...)737 t.cx--738 }739 case actSelectAll:740 if t.multi {741 for i := 0; i < t.merger.Length(); i++ {742 item := t.merger.Get(i)743 selectItem(item)744 }745 req(reqList, reqInfo)746 }747 case actDeselectAll:748 if t.multi {749 for i := 0; i < t.merger.Length(); i++ {750 item := t.merger.Get(i)751 delete(t.selected, item.index)752 }753 req(reqList, reqInfo)754 }755 case actToggle:756 if t.multi && t.merger.Length() > 0 {757 toggle()758 req(reqList)759 }760 case actToggleAll:761 if t.multi {762 for i := 0; i < t.merger.Length(); i++ {763 toggleY(i)764 }765 req(reqList, reqInfo)766 }767 case actToggleDown:768 if t.multi && t.merger.Length() > 0 {769 toggle()770 t.vmove(-1)
155 unmodified lines
modified:test/test_go.rb+23 added
541 unmodified lines
542 assert_equal lines.last, `find . | #{FZF} -e -f "^#{lines.last}$"`.chomp543 assert_equal lines.last, `find . -print0 | #{FZF} --null -e -f "^#{lines.last}$"`.chomp544 end545546 def test_select_all_deselect_all_toggle_all547 tmux.send_keys "seq 100 | #{fzf '--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --multi'}", :Enter548 tmux.until { |lines| lines[-2].include? '100/100' }549 tmux.send_keys :BTab, :BTab, :BTab550 tmux.until { |lines| lines[-2].include? '(3)' }551 tmux.send_keys 'C-t'552 tmux.until { |lines| lines[-2].include? '(97)' }553 tmux.send_keys 'C-a'554 tmux.until { |lines| lines[-2].include? '(100)' }555 tmux.send_keys :Tab, :Tab556 tmux.until { |lines| lines[-2].include? '(98)' }557 tmux.send_keys 'C-d'558 tmux.until { |lines| !lines[-2].include? '(' }559 tmux.send_keys :Tab, :Tab560 tmux.until { |lines| lines[-2].include? '(2)' }561 tmux.send_keys 0562 tmux.until { |lines| lines[-2].include? '10/100' }563 tmux.send_keys 'C-a'564 tmux.until { |lines| lines[-2].include? '(12)' }565 tmux.send_keys :Enter566 assert_equal %w[2 1 10 20 30 40 50 60 70 80 90 100], readonce.split($/)567 end568569private570 def writelines path, lines571 File.unlink path while File.exists? path572 File.open(path, 'w') { |f| f << lines.join($/) }
208 unmodified lines