Add 'show-preview' and 'hide-preview'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
For cases where 'toggle-preview' is not enough
authored by Junegunn Choi · committed by Junegunn Choi · parent 3ee00f8 · Browse files · 5 files·+62 added−3 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+62 added−3 removed
- tests:+39 added−0 removed
- other:+23 added−3 removed
Provenance
- Commit
aa2b9ec- Tree
0179c14- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
3ee00f8
5 files changed+62 added−3 removed
modified:man/man1/fzf.1+2 added
1034 unmodified lines1035 \fBpage-down\fR \fIpgdn\fR1036 \fBpage-up\fR \fIpgup\fR1037 \fBhalf-page-down\fR1038 \fBhalf-page-up\fR1039+ \fBhide-preview\fR1040 \fBpos(...)\fR (move cursor to the numeric position; negative number to count from the end)1041 \fBprev-history\fR (\fIctrl-p\fR on \fB--history\fR)1042 \fBprev-selected\fR (move to the previous selected item)1043 \fBpreview(...)\fR (see below for the details)14 unmodified lines1058 \fBreload-sync(...)\fR (see below for the details)1059 \fBreplace-query\fR (replace query string with the current selection)1060 \fBselect\fR1061 \fBselect-all\fR (select all matches)1062+ \fBshow-preview\fR1063 \fBtoggle\fR (\fIright-click\fR)1064 \fBtoggle-all\fR (toggle all matches)1065 \fBtoggle+down\fR \fIctrl-i (tab)\fR1066 \fBtoggle-in\fR (\fB--layout=reverse*\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)160 unmodified linesmodified:src/options.go+4 added
1109 unmodified lines1110 case "prev-selected":1111 appendAction(actPrevSelected)1112 case "next-selected":1113 appendAction(actNextSelected)1114+ case "show-preview":1115+ appendAction(actShowPreview)1116+ case "hide-preview":1117+ appendAction(actHidePreview)1118 case "toggle-preview":1119 appendAction(actTogglePreview)1120 case "toggle-preview-wrap":1121 appendAction(actTogglePreviewWrap)926 unmodified linesmodified:src/terminal.go+13 added-2 removed
348 unmodified lines349 actPrintQuery350 actRefreshPreview351 actReplaceQuery352 actToggleSort353+ actShowPreview354+ actHidePreview355 actTogglePreview356 actTogglePreviewWrap357 actTransformBorderLabel358 actTransformPreviewLabel2508 unmodified lines2867 t.executeCommand(a.a, true, false, false)2868 case actInvalid:2869 t.mutex.Unlock()2870 return false2869- case actTogglePreview:2870- if t.hasPreviewWindow() || len(t.previewOpts.command) > 0 {2871+ case actTogglePreview, actShowPreview, actHidePreview:2872+ var act bool2873+ switch a.t {2874+ case actShowPreview:2875+ act = !t.hasPreviewWindow() && len(t.previewOpts.command) > 02876+ case actHidePreview:2877+ act = t.hasPreviewWindow()2878+ case actTogglePreview:2879+ act = t.hasPreviewWindow() || len(t.previewOpts.command) > 02880+ }2881+ if act {2882 t.activePreviewOpts.Toggle()2883 updatePreviewWindow(false)2884 if t.isPreviewEnabled() {2885 valid, list := t.buildPlusList(t.previewOpts.command, false, false)692 unmodified linesmodified:test/test_go.rb+39 added
1493 unmodified lines1494 refute_includes lines[1], '║ [4]'1495 end1496 end1497 1498+ def test_show_and_hide_preview1499+ tmux.send_keys %(seq 100 | #{FZF} --preview-window hidden,border-bold --preview 'echo [{}]' --bind 'a:show-preview,b:hide-preview'), :Enter1500+1501+ # Hidden by default1502+ tmux.until do |lines|1503+ assert_equal 100, lines.match_count1504+ refute_includes lines[1], '┃ [1]'1505+ end1506+1507+ # Show1508+ tmux.send_keys :a1509+ tmux.until { |lines| assert_includes lines[1], '┃ [1]' }1510+1511+ # Already shown1512+ tmux.send_keys :a1513+ tmux.send_keys :Up1514+ tmux.until { |lines| assert_includes lines[1], '┃ [2]' }1515+1516+ # Hide1517+ tmux.send_keys :b1518+ tmux.send_keys :Up1519+ tmux.until do |lines|1520+ assert_includes lines, '> 3'1521+ refute_includes lines[1], '┃ [3]'1522+ end1523+1524+ # Already hidden1525+ tmux.send_keys :b1526+ tmux.send_keys :Up1527+ tmux.until do |lines|1528+ assert_includes lines, '> 4'1529+ refute_includes lines[1], '┃ [4]'1530+ end1531+1532+ # Show it again1533+ tmux.send_keys :a1534+ tmux.until { |lines| assert_includes lines[1], '┃ [4]' }1535+ end1536+1537 def test_preview_hidden1538 tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter1539 tmux.until { |lines| assert_equal '>', lines[-1] }1540 tmux.send_keys '?'1590 unmodified linesmodified:CHANGELOG.md+4 added-1 removed
1 CHANGELOG2 =========3 4-0.37.14+0.38.05 ------6+- New actions7+ - `show-preview`8+ - `hide-preview`9 - Bug fixes10 - `--preview-window 0,hidden` should not execute the preview command until11 `toggle-preview` action is triggered12 1539 unmodified lines