Add select and deselect actions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #2358
authored by Junegunn Choi · committed by Junegunn Choi · parent 806a47a · Browse files · 5 files·+60 added−0 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+60 added−0 removed
- tests:+21 added−0 removed
- other:+39 added−0 removed
Provenance
- Commit
76bbf57- Tree
5bea0fc- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
806a47a
5 files changed+60 added−0 removed
modified:man/man1/fzf.1+2 added
782 unmodified lines783 \fBclose\fR (close preview window if open, abort fzf otherwise)784 \fBclear-query\fR (clear query string)785 \fBdelete-char\fR \fIdel\fR786 \fBdelete-char/eof\fR \fIctrl-d\fR (same as \fBdelete-char\fR except aborts fzf if query is empty)787+ \fBdeselect\fR788 \fBdeselect-all\fR (deselect all matches)789 \fBdisable-search\fR (disable search functionality)790 \fBdown\fR \fIctrl-j ctrl-n down\fR791 \fBenable-search\fR (enable search functionality)27 unmodified lines819 \fBprint-query\fR (print query and exit)820 \fBrefresh-preview\fR821 \fBreload(...)\fR (see below for the details)822 \fBreplace-query\fR (replace query string with the current selection)823+ \fBselect\fR824 \fBselect-all\fR (select all matches)825 \fBtoggle\fR (\fIright-click\fR)826 \fBtoggle-all\fR (toggle all matches)827 \fBtoggle+down\fR \fIctrl-i (tab)\fR129 unmodified linesmodified:src/options.go+4 added
837 unmodified lines838 case "delete-char":839 appendAction(actDeleteChar)840 case "delete-char/eof":841 appendAction(actDeleteCharEOF)842+ case "deselect":843+ appendAction(actDeselect)844 case "end-of-line":845 appendAction(actEndOfLine)846 case "cancel":847 appendAction(actCancel)32 unmodified lines880 case "toggle-all":881 appendAction(actToggleAll)882 case "toggle-search":883 appendAction(actToggleSearch)884+ case "select":885+ appendAction(actSelect)886 case "select-all":887 appendAction(actSelectAll)888 case "deselect-all":889 appendAction(actDeselectAll)716 unmodified linesmodified:src/terminal.go+27 added
274 unmodified lines275 actLast276 actReload277 actDisableSearch278 actEnableSearch279+ actSelect280+ actDeselect281 )282 283 type placeholderFlags struct {284 plus bool1501 unmodified lines1786 1787 return true1788 }1789 1790+func (t *Terminal) selectItemChanged(item *Item) bool {1791+ if _, found := t.selected[item.Index()]; found {1792+ return false1793+ }1794+ return t.selectItem(item)1795+}1796+1797 func (t *Terminal) deselectItem(item *Item) {1798 delete(t.selected, item.Index())1799 t.version++1800 }1801 1802+func (t *Terminal) deselectItemChanged(item *Item) bool {1803+ if _, found := t.selected[item.Index()]; found {1804+ t.deselectItem(item)1805+ return true1806+ }1807+ return false1808+}1809+1810 func (t *Terminal) toggleItem(item *Item) bool {1811 if _, found := t.selected[item.Index()]; !found {1812 return t.selectItem(item)1813 }543 unmodified lines2357 togglePreview(false)2358 } else {2359 req(reqQuit)2360 }2361+ case actSelect:2362+ current := t.currentItem()2363+ if t.multi > 0 && current != nil && t.selectItemChanged(current) {2364+ req(reqList, reqInfo)2365+ }2366+ case actDeselect:2367+ current := t.currentItem()2368+ if t.multi > 0 && current != nil && t.deselectItemChanged(current) {2369+ req(reqList, reqInfo)2370+ }2371 case actToggle:2372 if t.multi > 0 && t.merger.Length() > 0 && toggle() {2373 req(reqList)2374 }340 unmodified linesmodified:test/test_go.rb+21 added
1888 unmodified lines1889 tmux.send_keys 'C-c'1890 tmux.send_keys 'C-l', 'closed'1891 tmux.until { |lines| assert_includes lines[0], 'closed' }1892 end1893+1894+ def test_select_deselect1895+ tmux.send_keys "seq 3 | #{FZF} --multi --bind up:deselect+up,down:select+down", :Enter1896+ tmux.until { |lines| assert_equal 3, lines.match_count }1897+ tmux.send_keys :Tab1898+ tmux.until { |lines| assert_equal 1, lines.select_count }1899+ tmux.send_keys :Up1900+ tmux.until { |lines| assert_equal 0, lines.select_count }1901+ tmux.send_keys :Down, :Down1902+ tmux.until { |lines| assert_equal 2, lines.select_count }1903+ tmux.send_keys :Tab1904+ tmux.until { |lines| assert_equal 1, lines.select_count }1905+ tmux.send_keys :Down, :Down1906+ tmux.until { |lines| assert_equal 2, lines.select_count }1907+ tmux.send_keys :Up1908+ tmux.until { |lines| assert_equal 1, lines.select_count }1909+ tmux.send_keys :Down1910+ tmux.until { |lines| assert_equal 1, lines.select_count }1911+ tmux.send_keys :Down1912+ tmux.until { |lines| assert_equal 2, lines.select_count }1913+ end1914 end1915 1916 module TestShell1917 def setup478 unmodified linesmodified:CHANGELOG.md+6 added
1 CHANGELOG2 =========3 4+0.25.25+------6+- Added `select` and `deselect` action for unconditinoally selecting or7+ deselecting a single item in `--multi` mode. Complements `toggle` action.8+- Built with Go 1.169+10 0.25.111 ------12 - Added `close` action13 - Close preview window if open, abort fzf otherwise1075 unmodified lines