Add --preview-window=next position

Places preview adjacent to input on the list side: above input in the
default layout, below it in --layout=reverse.

  fzf --preview 'cat {}' --preview-window=next

Close #4798
This commit is contained in:
Junegunn Choi
2026-05-21 20:29:37 +09:00
parent 67319aed0b
commit b6347a9498
5 changed files with 344 additions and 153 deletions
+13 -4
View File
@@ -160,7 +160,7 @@ Usage: fzf [options]
PREVIEW WINDOW
--preview=COMMAND Command to preview highlighted line ({})
--preview-window=OPT Preview window layout (default: right:50%)
[up|down|left|right][,SIZE[%]]
[up|down|left|right|next][,SIZE[%]]
[,[no]wrap[-word]][,[no]cycle][,[no]follow][,[no]info]
[,[no]hidden][,border-STYLE]
[,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]
@@ -332,6 +332,7 @@ const (
posLeft
posRight
posCenter
posNext // adjacent to the input section, on the list side
)
type tmuxOptions struct {
@@ -391,7 +392,7 @@ func (o *previewOpts) Toggle() {
o.hidden = !o.hidden
}
func (o *previewOpts) Border() tui.BorderShape {
func (o *previewOpts) Border(layout layoutType) tui.BorderShape {
shape := o.border
if shape == tui.BorderLine {
switch o.position {
@@ -403,6 +404,12 @@ func (o *previewOpts) Border() tui.BorderShape {
shape = tui.BorderRight
case posRight:
shape = tui.BorderLeft
case posNext:
if layout == layoutReverse {
shape = tui.BorderBottom
} else {
shape = tui.BorderTop
}
}
}
return shape
@@ -512,7 +519,7 @@ func parseLabelPosition(opts *labelOpts, arg string) error {
}
func (a previewOpts) aboveOrBelow() bool {
return a.size.size > 0 && (a.position == posUp || a.position == posDown)
return a.size.size > 0 && (a.position == posUp || a.position == posDown || a.position == posNext)
}
type previewOptsCompare int
@@ -2352,6 +2359,8 @@ func parsePreviewWindowImpl(opts *previewOpts, input string) error {
opts.position = posLeft
case "right":
opts.position = posRight
case "next":
opts.position = posNext
case "rounded", "border", "border-rounded":
opts.border = tui.BorderRounded
case "border-line":
@@ -3158,7 +3167,7 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
case "--no-preview":
opts.Preview.command = ""
case "--preview-window":
str, err := nextString("preview window layout required: [up|down|left|right][,SIZE[%]][,border-STYLE][,wrap][,cycle][,hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default]")
str, err := nextString("preview window layout required: [up|down|left|right|next][,SIZE[%]][,border-STYLE][,wrap][,cycle][,hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default]")
if err != nil {
return err
}