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
Provenance
- Commit
d9752a4- Tree
fc37e3e- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
dba14d2
4 files changed+41 added−14 removed
modified:man/man1/fzf.1+26 added-11 removed
379 unmodified lines380 Preview window will be updated even when there is no match for the current381 query 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]]"385-Determines the layout of the preview window. If the argument contains384+.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:wrap][:cycle][:hidden][:+SCROLL[-OFFSET]]"385+386+.RS387+.B POSITION: (default: right)388+ \fBup389+ \fBdown390+ \fBleft391+ \fBright392+.RE393+394+\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.388-Line wrap can be enabled with \fB:wrap\fR flag.397+Line wrap can be enabled with \fB:wrap\fR flag. Cyclic scrolling is enabled398+with \fB:cycle\fR flag.399 400 If size is given as 0, preview window will not be visible, but fzf will still401 execute the command in the background.402 8 unmodified lines411 be 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.413 414 .RS405-.B POSITION: (default: right)406- \fBup407- \fBdown408- \fBleft409- \fBright410-.RE411-412-.RS415 e.g.416 \fB# Non-default scroll window positions and sizes417 fzf --preview="head {}" --preview-window=up:30%418 fzf --preview="file {}" --preview-window=down:19 unmodified lines428 --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \\429 --preview-window +{2}-/2\fR430 431 .RE432+433+You can write style-related flags across multiple \fB--preview-window\fR434+options. But flags that are not style-related such as \fBhidden\fR and scroll435+offset are only allowed in the last \fB--preview-window\fR.436+437+.RS438+e.g.439+ export FZF_DEFAULT_OPTS='--preview-window sharp:cycle'440+441+ # sharp + cycle + up + 50%442+ fzf --preview-window 'up' --preview-window '50%' --preview 'bat {}'443+.RE444+445 .SS Scripting446 .TP447 .BI "-q, --query=" "STR"448 Start the finder with the given query414 unmodified linesmodified:src/options_test.go+5 added-3 removed
385 unmodified lines386 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 linesmodified:src/options.go+4 added
992 unmodified lines993 return infoDefault994 }995 996 func parsePreviewWindow(opts *previewOpts, input string) {997+ // We should reset flags that are not style-related.998+ opts.hidden = false999+ opts.scroll = ""1000+1001 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 linesmodified:CHANGELOG.md+6 added
1 CHANGELOG2 =========3 4+0.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.9+10 0.23.011 ------12 - Support preview scroll offset relative to window height13 ```sh930 unmodified lines