Skip to content
Myr

Reset preview window flags that are not style-related

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

Fix #2203

authored by Junegunn Choi · committed by Junegunn Choi · parent dba14d2 · Browse files · 4 files+41 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

4 files+41 added−14 removed

  • other:+41 added−14 removed

4 files+41 added−14 removed

modified:man/man1/fzf.1+26 added-11 removed
379 unmodified lines
380Preview window will be updated even when there is no match for the current381query if any of the placeholder expressions evaluates to a non-empty string.382.RE383.TP384.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"385Determines the layout of the preview window. If the argument contains384.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:wrap][:cycle][:hidden][:+SCROLL[-OFFSET]]"385386.RS387.B POSITION: (default: right)388 \fBup389 \fBdown390 \fBleft391 \fBright392.RE393394\fRDetermines the layout of the preview window. If the argument contains395\fB:hidden\fR, the preview window will be hidden by default until396\fBtoggle-preview\fR action is triggered. Long lines are truncated by default.388Line wrap can be enabled with \fB:wrap\fR flag.397Line wrap can be enabled with \fB:wrap\fR flag. Cyclic scrolling is enabled398with \fB:cycle\fR flag.399400If size is given as 0, preview window will not be visible, but fzf will still401execute the command in the background.402
8 unmodified lines
411be given as a numeric integer (\fB-INTEGER\fR), or as a denominator form412(\fB-/INTEGER\fR) for specifying a fraction of the preview window height.413414.RS405.B POSITION: (default: right)406 \fBup407 \fBdown408 \fBleft409 \fBright410.RE411412.RS415e.g.416 \fB# Non-default scroll window positions and sizes417 fzf --preview="head {}" --preview-window=up:30%418 fzf --preview="file {}" --preview-window=down:1
9 unmodified lines
428 --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \\429 --preview-window +{2}-/2\fR430431.RE432433You can write style-related flags across multiple \fB--preview-window\fR434options. But flags that are not style-related such as \fBhidden\fR and scroll435offset are only allowed in the last \fB--preview-window\fR.436437.RS438e.g.439 export FZF_DEFAULT_OPTS='--preview-window sharp:cycle'440441 # sharp + cycle + up + 50%442 fzf --preview-window 'up' --preview-window '50%' --preview 'bat {}'443.RE444445.SS Scripting446.TP447.BI "-q, --query=" "STR"448Start the finder with the given query
414 unmodified lines
modified:src/options_test.go+5 added-3 removed
385 unmodified lines
386 opts.Preview.size.percent == true &&387 opts.Preview.size.size == 50) {388 t.Error()389 }390 opts = optsFor("--preview", "cat {}", "--preview-window=left:15:hidden:wrap")390 opts = optsFor("--preview", "cat {}", "--preview-window=left:15:hidden:wrap:+{1}-/2")391 if !(opts.Preview.command == "cat {}" &&392 opts.Preview.hidden == true &&393 opts.Preview.wrap == true &&394 opts.Preview.position == posLeft &&395 opts.Preview.scroll == "{1}-/2" &&396 opts.Preview.size.percent == false &&397 opts.Preview.size.size == 15) {398 t.Error(opts.Preview)399 }399 opts = optsFor("--preview-window=up:15:wrap:hidden", "--preview-window=down", "--preview-window=cycle")400 opts = optsFor("--preview-window=up:15:wrap:hidden:+{1}-/2", "--preview-window=down", "--preview-window=cycle")401 if !(opts.Preview.command == "" &&401 opts.Preview.hidden == true &&402 opts.Preview.hidden == false &&403 opts.Preview.wrap == true &&404 opts.Preview.cycle == true &&405 opts.Preview.position == posDown &&406 opts.Preview.scroll == "" &&407 opts.Preview.size.percent == false &&408 opts.Preview.size.size == 15) {409 t.Error(opts.Preview.size.size)410 }
43 unmodified lines
modified:src/options.go+4 added
992 unmodified lines
993 return infoDefault994}995996func parsePreviewWindow(opts *previewOpts, input string) {997 // We should reset flags that are not style-related.998 opts.hidden = false999 opts.scroll = ""10001001 tokens := strings.Split(input, ":")1002 sizeRegex := regexp.MustCompile("^[0-9]+%?$")1003 offsetRegex := regexp.MustCompile("^\\+([0-9]+|{-?[0-9]+})(-[0-9]+|-/[1-9][0-9]*)?$")1004 for _, token := range tokens {
484 unmodified lines
modified:CHANGELOG.md+6 added
1CHANGELOG2=========340.23.15------6- Reset `hidden` flag and scroll offset of `--preview-window` if another7 `--preview-window` is found. We should only keep style-related flags across8 multiple `--preview-window` options.9100.23.011------12- Support preview scroll offset relative to window height13 ```sh
930 unmodified lines