Add --preview-window=next position (#4801)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
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
authored by Junegunn Choi · committed by GitHub · parent 67319ae · Browse files · 5 files·+396 added−171 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+396 added−171 removed
- tests:+175 added−60 removed
- other:+221 added−111 removed
Provenance
- Commit
677e854- Tree
f7ce6b3- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
67319ae
5 files changed+396 added−171 removed
modified:man/man1/fzf.1+5 added
991 unmodified lines992 \fBup993 \fBdown994 \fBleft995 \fBright996+ \fBnext997 998 \fRDetermines the layout of the preview window.999 1000+* \fBnext\fR places the preview window adjacent to the input section, on1001+the list side: above the input in the default layout, below the input1002+in \fB\-\-layout=reverse\fR.1003+1004 * If the argument contains \fB:hidden\fR, the preview window will be hidden by1005 default until \fBtoggle\-preview\fR action is triggered.1006 1007 * If size is given as 0, preview window will not be visible, but fzf will still1318 unmodified linesmodified:src/options.go+13 added-4 removed
158 unmodified lines159 160 PREVIEW WINDOW161 --preview=COMMAND Command to preview highlighted line ({})162 --preview-window=OPT Preview window layout (default: right:50%)163- [up|down|left|right][,SIZE[%]]163+ [up|down|left|right|next][,SIZE[%]]164 [,[no]wrap[-word]][,[no]cycle][,[no]follow][,[no]info]165 [,[no]hidden][,border-STYLE]166 [,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]167 [,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]163 unmodified lines331 posDown332 posLeft333 posRight334 posCenter335+ posNext // adjacent to the input section, on the list side336 )337 338 type tmuxOptions struct {339 width sizeSpec51 unmodified lines391 func (o *previewOpts) Toggle() {392 o.hidden = !o.hidden393 }394 394-func (o *previewOpts) Border() tui.BorderShape {395+func (o *previewOpts) Border(layout layoutType) tui.BorderShape {396 shape := o.border397 if shape == tui.BorderLine {398 switch o.position {399 case posUp:3 unmodified lines403 case posLeft:404 shape = tui.BorderRight405 case posRight:406 shape = tui.BorderLeft407+ case posNext:408+ if layout == layoutReverse {409+ shape = tui.BorderBottom410+ } else {411+ shape = tui.BorderTop412+ }413 }414 }415 return shape416 }101 unmodified lines518 return err519 }520 521 func (a previewOpts) aboveOrBelow() bool {515- return a.size.size > 0 && (a.position == posUp || a.position == posDown)522+ return a.size.size > 0 && (a.position == posUp || a.position == posDown || a.position == posNext)523 }524 525 type previewOptsCompare int526 1831 unmodified lines2358 case "left":2359 opts.position = posLeft2360 case "right":2361 opts.position = posRight2362+ case "next":2363+ opts.position = posNext2364 case "rounded", "border", "border-rounded":2365 opts.border = tui.BorderRounded2366 case "border-line":2367 opts.border = tui.BorderLine798 unmodified lines3166 }3167 case "--no-preview":3168 opts.Preview.command = ""3169 case "--preview-window":3161- str, err := nextString("preview window layout required: [up|down|left|right][,SIZE[%]][,border-STYLE][,wrap][,cycle][,hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default]")3170+ str, err := nextString("preview window layout required: [up|down|left|right|next][,SIZE[%]][,border-STYLE][,wrap][,cycle][,hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default]")3171 if err != nil {3172 return err3173 }3174 if err := parsePreviewWindow(&opts.Preview, str); err != nil {811 unmodified linesmodified:src/terminal.go+202 added-107 removed
986 unmodified lines987 maxHeightFunc := func(termHeight int) int {988 // Minimum height required to render fzf excluding margin and padding989 effectiveMinHeight := minHeight990 if previewBox != nil && opts.Preview.aboveOrBelow() {991- effectiveMinHeight += 1 + borderLines(opts.Preview.Border())991+ effectiveMinHeight += 1 + borderLines(opts.Preview.Border(opts.Layout))992 }993 if opts.noSeparatorLine() {994 effectiveMinHeight--995 }655 unmodified lines1651 output := func() {1652 wrap := t.wrap1653 t.wrap = false1654 t.withWindow(t.inputWindow, func() {1655- line := t.promptLine()1655 preTask := func(markerClass) int {1656 return 11657 }1658 t.printHighlighted(1660- Result{item: item}, tui.ColPrompt, tui.ColPrompt, false, false, false, line, line, true, preTask, nil, 0)1659+ Result{item: item}, tui.ColPrompt, tui.ColPrompt, false, false, false, 0, 0, true, preTask, nil, 0)1660 })1661 t.wrap = wrap1662 }1663 _, promptLen := t.processTabsStr(trimmed, 0)439 unmodified lines2103 return util.Constrain(int(size.size)+minSize-1, minSize, max)2104 }2105 2106 func (t *Terminal) minPreviewSize(opts *previewOpts) (int, int) {2107+ border := opts.Border(t.layout)2108- minPreviewWidth := 1 + borderColumns(opts.Border(), t.borderWidth)2109- minPreviewHeight := 1 + borderLines(opts.Border())2108+ minPreviewWidth := 1 + borderColumns(border, t.borderWidth)2109+ minPreviewHeight := 1 + borderLines(border)2110 2111 switch opts.position {2112 case posLeft, posRight:2113- if len(t.scrollbar) > 0 && !opts.Border().HasRight() {2113+ if len(t.scrollbar) > 0 && !border.HasRight() {2114 // Need a column to show scrollbar2115 minPreviewWidth++2116 }2117 }76 unmodified lines2194 }2195 if t.needPreviewWindow() {2196 minPreviewWidth, minPreviewHeight := t.minPreviewSize(t.activePreviewOpts)2197 switch t.activePreviewOpts.position {2198- case posUp, posDown:2198+ case posUp, posDown, posNext:2199 minAreaHeight += minPreviewHeight2200 minAreaWidth = max(minPreviewWidth, minAreaWidth)2201 case posLeft, posRight:2202 minAreaWidth += minPreviewWidth16 unmodified lines2219 }2220 if t.hasHeaderLinesWindow() {2221 return len(t.header0) > 02222 }2223- if t.headerBorderShape.Visible() {2223+ if t.headerBorderShape.Visible() || t.headerFirst {2224 return len(t.header0)+t.headerLines > 02225 }2226 return t.inputBorderShape.Visible()2227 }29 unmodified lines2257 }2258 2259 // Use header window instead2260 if len(t.header0) == 0 {2261+ if t.headerFirst && shape == tui.BorderPhantom {2262+ return true, shape2263+ }2264 return false, t.headerBorderShape2265 }2266 2267 // We have both types of headers, and we want to separate the two184 unmodified lines2452 shrink := 02453 hasHeaderWindow := t.hasHeaderWindow()2454 hasFooterWindow := len(t.footer) > 02455 hasHeaderLinesWindow, headerLinesShape := t.determineHeaderLinesShape()2456+ // computePreviewSize returns the size resizePreviewWindows will compute2457+ // for opts and the minimum size for that axis: height/minPreviewHeight2458+ // for vertical positions, width/minPreviewWidth for horizontal.2459+ computePreviewSize := func(opts *previewOpts) (int, int) {2460+ minPreviewWidth, minPreviewHeight := t.minPreviewSize(opts)2461+ switch opts.position {2462+ case posUp, posDown, posNext:2463+ minWindowHeight := minHeight2464+ if t.inputless {2465+ minWindowHeight--2466+ }2467+ if t.noSeparatorLine() {2468+ minWindowHeight--2469+ }2470+ return calculateSize(height, opts.size, minWindowHeight, minPreviewHeight), minPreviewHeight2471+ case posLeft, posRight:2472+ minListWidth := minWidth2473+ if t.listBorderShape.HasLeft() {2474+ minListWidth += 22475+ }2476+ if t.listBorderShape.HasRight() {2477+ minListWidth++2478+ }2479+ return calculateSize(width, opts.size, minListWidth, minPreviewWidth), minPreviewWidth2480+ }2481+ return 0, 02482+ }2483+ // Walk the threshold chain to determine the previewOpts that2484+ // resizePreviewWindows will actually settle on. We need this here2485+ // because hasInputWindow and the availableLines adjustment below run2486+ // before resizePreviewWindows, and t.activePreviewOpts still holds the2487+ // previous frame's resolution.2488+ effectivePreviewOpts := &t.previewOpts2489+ if t.needPreviewWindow() {2490+ opts := &t.previewOpts2491+ for {2492+ if opts.size.size == 0 || opts.threshold <= 0 || opts.alternative == nil {2493+ break2494+ }2495+ if actual, _ := computePreviewSize(opts); actual >= opts.threshold {2496+ break2497+ }2498+ opts = opts.alternative2499+ if opts.hidden {2500+ break2501+ }2502+ }2503+ effectivePreviewOpts = opts2504+ }2453- hasInputWindow := !t.inputless && (t.inputBorderShape.Visible() || hasHeaderWindow || hasHeaderLinesWindow)2505+ hasInputWindow := !t.inputless && (t.inputBorderShape.Visible() || hasHeaderWindow || hasHeaderLinesWindow || effectivePreviewOpts.position == posNext)2506 inputWindowHeight := 22507 if t.noSeparatorLine() {2508 inputWindowHeight--2509 }11 unmodified lines2521 }2522 2523 // FIXME: Needed?2524 if t.needPreviewWindow() {2473- _, minPreviewHeight := t.minPreviewSize(t.activePreviewOpts)2474- switch t.activePreviewOpts.position {2475- case posUp, posDown:2525+ switch effectivePreviewOpts.position {2526+ case posUp, posDown, posNext:2527+ _, minPreviewHeight := t.minPreviewSize(effectivePreviewOpts)2528 availableLines -= minPreviewHeight2529 }2530 }2531 143 unmodified lines2675 2676 // Set up preview window2677 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)2678 cleanLeft := []int{}2679+ // previewNextSize is pheight when the preview is placed adjacent to2680+ // the input (position == "next"); inputBorderTop() reads it through the2681+ // closure to push input past the preview band.2682+ previewNextSize := 02683+ // inputBorderTop returns the canvas Y at which the input border window2684+ // should be placed. It depends on wborder/t.window (set by the preview2685+ // case), the layout, --header-first, and previewNextSize (set when2686+ // posNext is active). Used both for placing the preview adjacent to2687+ // input and later for placing the input window itself.2688+ inputBorderTop := func() int {2689+ w := t.wborder2690+ if w == nil {2691+ w = t.window2692+ }2693+ hasSeparateHeader := hasHeaderWindow && t.headerBorderShape != tui.BorderInline2694+ hasSeparateHeaderLines := hasHeaderLinesWindow && headerLinesShape != tui.BorderInline2695+ if (hasSeparateHeader || hasSeparateHeaderLines) && t.headerFirst {2696+ switch t.layout {2697+ case layoutDefault:2698+ btop := w.Top() + w.Height() + previewNextSize2699+ if hasHeaderWindow && hasHeaderLinesWindow {2700+ btop += headerLinesHeight2701+ }2702+ return btop2703+ case layoutReverse:2704+ btop := w.Top() - inputBorderHeight - previewNextSize2705+ if hasHeaderWindow && hasHeaderLinesWindow {2706+ btop -= headerLinesHeight2707+ }2708+ return btop2709+ case layoutReverseList:2710+ return w.Top() + w.Height() + previewNextSize2711+ }2712+ }2713+ switch t.layout {2714+ case layoutDefault:2715+ return w.Top() + w.Height() + headerBorderHeight + headerLinesHeight + previewNextSize2716+ case layoutReverse:2717+ return w.Top() - shrink + footerBorderHeight - previewNextSize2718+ case layoutReverseList:2719+ return w.Top() + w.Height() + headerBorderHeight + previewNextSize2720+ }2721+ return 02722+ }2723 if forcePreview || t.needPreviewWindow() {2724 var resizePreviewWindows func(previewOpts *previewOpts)2725 resizePreviewWindows = func(previewOpts *previewOpts) {2726 t.activePreviewOpts = previewOpts3 unmodified lines2730 hasThreshold := previewOpts.threshold > 0 && previewOpts.alternative != nil2731 createPreviewWindow := func(y int, x int, w int, h int) {2732 pwidth := w2733 pheight := h2638- shape := previewOpts.Border()2734+ shape := previewOpts.Border(t.layout)2735 previewBorder := tui.MakeBorderStyle(shape, t.unicode)2736 t.pborder = t.tui.NewWindow(y, x, w, h, tui.WindowPreview, previewBorder, false)2737 pwidth -= borderColumns(shape, bw)2738 pheight -= borderLines(shape)12 unmodified lines2751 if !hadPreviewWindow {2752 t.pwindow.Erase()2753 }2754 }2659- minPreviewWidth, minPreviewHeight := t.minPreviewSize(previewOpts)2660- switch previewOpts.position {2661- case posUp, posDown:2662- minWindowHeight := minHeight2663- if t.inputless {2664- minWindowHeight--2665- }2666- if t.noSeparatorLine() {2667- minWindowHeight--2668- }2669- pheight := calculateSize(height, previewOpts.size, minWindowHeight, minPreviewHeight)2755+ // Shared boilerplate for vertical positions (posUp/posDown/posNext):2756+ // compute pheight, apply the threshold alternative, honor hidden,2757+ // and update listStickToRight. Returns (pheight, true) when the2758+ // caller should return early.2759+ computeVerticalSize := func() (int, bool) {2760+ pheight, minPreviewHeight := computePreviewSize(previewOpts)2761 if hasThreshold && pheight < previewOpts.threshold {2762 t.activePreviewOpts = previewOpts.alternative2763 if forcePreview {2764 previewOpts.alternative.hidden = false2765 }2766 if !previewOpts.alternative.hidden {2767 resizePreviewWindows(previewOpts.alternative)2768 }2678- return2769+ return 0, true2770 }2771 if forcePreview {2772 previewOpts.hidden = false2773 }2774 if previewOpts.hidden {2684- return2775+ return 0, true2776 }2686-2687- listStickToRight = listStickToRight && !previewOpts.Border().HasRight()2777+ listStickToRight = listStickToRight && !previewOpts.Border(t.layout).HasRight()2778 if listStickToRight {2779 innerWidth++2780 width++2781 }2782+ return util.Constrain(pheight, minPreviewHeight, availableLines), false2783+ }2784+ switch previewOpts.position {2785+ case posUp, posDown:2786+ pheight, done := computeVerticalSize()2787+ if done {2788+ return2789+ }2790 2693- pheight = util.Constrain(pheight, minPreviewHeight, availableLines)2694-2791 if previewOpts.position == posUp {2792 innerBorderFn(marginInt[0]+pheight, marginInt[3], width, height-pheight)2793 t.window = t.tui.NewWindow(2794 innerMarginInt[0]+pheight+shift+inlineTopLines, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)3 unmodified lines2798 t.window = t.tui.NewWindow(2799 innerMarginInt[0]+shift+inlineTopLines, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2800 createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)2801 }2706- case posLeft, posRight:2707- minListWidth := minWidth2708- if t.listBorderShape.HasLeft() {2709- minListWidth += 22802+ case posNext:2803+ pheight, done := computeVerticalSize()2804+ if done {2805+ return2806 }2711- if t.listBorderShape.HasRight() {2712- minListWidth++2807+ previewNextSize = pheight2808+2809+ if t.layout == layoutReverse {2810+ // [(header)][input][preview]([header])[list]: reuse posUp's2811+ // wborder/list math; input is pulled back up by pheight in2812+ // its positioning. Preview sits directly below input.2813+ innerBorderFn(marginInt[0]+pheight, marginInt[3], width, height-pheight)2814+ t.window = t.tui.NewWindow(2815+ innerMarginInt[0]+pheight+shift+inlineTopLines, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2816+ createPreviewWindow(inputBorderTop()+inputBorderHeight, marginInt[3], width, pheight)2817+ } else {2818+ // [list]([header])[preview][input][(header)]: reuse posDown's2819+ // wborder/list math; input is pushed down by pheight in its2820+ // positioning. Preview sits directly above input.2821+ innerBorderFn(marginInt[0], marginInt[3], width, height-pheight)2822+ t.window = t.tui.NewWindow(2823+ innerMarginInt[0]+shift+inlineTopLines, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2824+ createPreviewWindow(inputBorderTop()-pheight, marginInt[3], width, pheight)2825 }2714- pwidth := calculateSize(width, previewOpts.size, minListWidth, minPreviewWidth)2826+ case posLeft, posRight:2827+ pwidth, _ := computePreviewSize(previewOpts)2828 if hasThreshold && pwidth < previewOpts.threshold {2829 t.activePreviewOpts = previewOpts.alternative2830 if forcePreview {2831 previewOpts.alternative.hidden = false23 unmodified lines2855 innerMarginInt[0]+shift+inlineTopLines, innerMarginInt[3]+pwidth+m, innerWidth-pwidth-m, innerHeight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2856 2857 // Clear characters on the margin2858 // fzf --bind 'space:toggle-preview' --preview ':' --preview-window left,1,border-none --footer-border --footer f --header h --header-border2746- if !previewOpts.Border().HasRight() {2859+ if !previewOpts.Border(t.layout).HasRight() {2860 cleanLeft = append(cleanLeft, -2)2861 }2862 // fzf --bind 'space:toggle-preview' --preview ':' --preview-window left,1 --footer-border --footer f --header h --header-border2863 if !hasListBorder {6 unmodified lines2870 // NOTE: Relaxed condition for the following cases2871 // fzf --preview 'seq 500' --preview-window border-left --border2872 // fzf --preview 'seq 500' --preview-window border-left --border --list-border2873 // fzf --preview 'seq 500' --preview-window border-left --border --input-border2761- listStickToRight = t.borderShape.HasRight() && !previewOpts.Border().HasRight()2874+ listStickToRight = t.borderShape.HasRight() && !previewOpts.Border(t.layout).HasRight()2875 if listStickToRight {2876 innerWidth++2877 width++2878 }80 unmodified lines2959 w = t.window2960 }2961 2962 if hasInputWindow {2850- var btop int2851- // Inline sections live inside the list frame, so they don't participate2852- // in --header-first repositioning; only non-inline sections do.2853- hasNonInlineHeader := hasHeaderWindow && t.headerBorderShape != tui.BorderInline2854- hasNonInlineHeaderLines := hasHeaderLinesWindow && headerLinesShape != tui.BorderInline2855- if (hasNonInlineHeader || hasNonInlineHeaderLines) && t.headerFirst {2856- switch t.layout {2857- case layoutDefault:2858- btop = w.Top() + w.Height()2859- // If both headers are present, the header lines are displayed with the list2860- if hasHeaderWindow && hasHeaderLinesWindow {2861- btop += headerLinesHeight2862- }2863- case layoutReverse:2864- btop = w.Top() - inputBorderHeight2865- if hasHeaderWindow && hasHeaderLinesWindow {2866- btop -= headerLinesHeight2867- }2868- case layoutReverseList:2869- btop = w.Top() + w.Height()2870- }2871- } else {2872- switch t.layout {2873- case layoutDefault:2874- btop = w.Top() + w.Height() + headerBorderHeight + headerLinesHeight2875- case layoutReverse:2876- btop = w.Top() - shrink + footerBorderHeight2877- case layoutReverseList:2878- btop = w.Top() + w.Height() + headerBorderHeight2879- }2880- }2963+ btop := inputBorderTop()2964 shift := 02965 if !t.inputBorderShape.HasLeft() && t.listBorderShape.HasLeft() {2966 shift += t.borderWidth + 12967 }15 unmodified lines2983 if hasHeaderWindow && t.headerBorderShape != tui.BorderInline {2984 var btop int2985 if hasInputWindow && t.headerFirst {2986 if t.layout == layoutReverse {2904- btop = w.Top() - shrink + footerBorderHeight2987+ btop = w.Top() - shrink + footerBorderHeight - previewNextSize2988 } else if t.layout == layoutReverseList {2906- btop = w.Top() + w.Height() + inputBorderHeight2989+ btop = w.Top() + w.Height() + inputBorderHeight + previewNextSize2990 } else {2908- btop = w.Top() + w.Height() + inputBorderHeight + headerLinesHeight2991+ btop = w.Top() + w.Height() + inputBorderHeight + headerLinesHeight + previewNextSize2992 }2993 } else {2994 if t.layout == layoutReverse {2995 btop = w.Top() - headerBorderHeight - headerLinesHeight22 unmodified lines3018 headerFirst := t.headerFirst && len(t.header0) == 03019 3020 if headerFirst {3021 if t.layout == layoutDefault {2939- btop = w.Top() + w.Height() + inputBorderHeight3022+ btop = w.Top() + w.Height() + inputBorderHeight + previewNextSize3023 } else if t.layout == layoutReverse {3024 btop = w.Top() - headerLinesHeight - inputBorderHeight3025 } else {3026 btop = w.Top() - headerLinesHeight59 unmodified lines3086 listLabel, listLabelLen = t.ansiLabelPrinter(t.listLabelOpts.label, &custom, false)3087 }3088 t.printLabel(t.wborder, listLabel, t.listLabelOpts, listLabelLen, t.listBorderShape, false)3089 t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, false)3007- t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), false)3090+ t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(t.layout), false)3091 t.printLabel(t.inputBorder, t.inputLabel, t.inputLabelOpts, t.inputLabelLen, t.inputBorderShape, false)3092 t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, false)3093 t.printLabel(t.footerBorder, t.footerLabel, t.footerLabelOpts, t.footerLabelLen, t.footerBorderShape, false)3094 }100 unmodified lines3195 t.queryLen = [2]int{beforeLen, afterLen}3196 return before, after3197 }3198 3116-func (t *Terminal) promptLine() int {3117- if t.inputWindow != nil {3118- return 03119- }3120- if t.headerFirst {3121- max := t.window.Height() - 13122- if max <= 0 { // Extremely short terminal3123- return 03124- }3125- if !t.noSeparatorLine() {3126- max--3127- }3128- return min(t.visibleHeaderLinesInList(), max)3129- }3130- return 03131-}3132-3199 func (t *Terminal) placeCursor() {3200 if t.inputless {3201 return3202 }7 unmodified lines3210 t.inputWindow.Move(y, x)3211 return3212 }3213 x = min(x, t.window.Width()-1)3148- t.move(t.promptLine(), x, false)3214+ t.move(0, x, false)3215 }3216 3217 func (t *Terminal) printPrompt() {3218 if t.inputless {45 unmodified lines3264 if t.window.Width() <= 1 || t.window.Height() == 0 {3265 return3266 }3267 pos := 03202- line := t.promptLine()3268+ line := 03269 maxHeight := t.window.Height()3270 move := func(y int, x int, clear bool) bool {3271 if y < 0 || y >= maxHeight {3272 return false326 unmodified lines3599 }3600 3601 func (t *Terminal) printHeaderImpl(window tui.Window, borderShape tui.BorderShape, lines1 []string, lines2 []Item) {3602 max := t.window.Height()3537- if !t.inputless && t.inputWindow == nil && window == nil && t.headerFirst {3538- max--3539- if !t.noSeparatorLine() {3540- max--3541- }3542- }3603 var state *ansiState3604 needReverse := false3605 switch t.layout {3606 case layoutDefault, layoutReverseList:1335 unmodified lines4942 t.previewer.bar = make([]bool, height)4943 t.previewer.xw = xw4944 }4945 xshift := -1 - t.borderWidth4886- if !t.activePreviewOpts.Border().HasRight() {4946+ if !t.activePreviewOpts.Border(t.layout).HasRight() {4947 xshift = -14948 }4949 yshift := 14890- if !t.activePreviewOpts.Border().HasTop() {4950+ if !t.activePreviewOpts.Border(t.layout).HasTop() {4951 yshift = 04952 }4953 for i := yoff; i < height; i++ {4954 x := w + xshift968 unmodified lines5923 if t.needPreviewWindow() {5924 if t.activePreviewOpts.aboveOrBelow() {5925 if t.activePreviewOpts.size.percent {5926 newContentHeight := int(float64(contentHeight) * 100. / (100. - t.activePreviewOpts.size.size))5867- contentHeight = max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight)5927+ contentHeight = max(contentHeight+1+borderLines(t.activePreviewOpts.Border(t.layout)), newContentHeight)5928 } else {5869- contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.Border())5929+ contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.Border(t.layout))5930 }5931 } else {5932 // Minimum height if preview window can appear5873- contentHeight = max(contentHeight, 1+borderLines(t.activePreviewOpts.Border()))5933+ contentHeight = max(contentHeight, 1+borderLines(t.activePreviewOpts.Border(t.layout)))5934 }5935 }5936 return min(termHeight, contentHeight+pad)5937 })373 unmodified lines6311 }6312 case reqRedrawBorderLabel:6313 t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true)6314 case reqRedrawPreviewLabel:6255- t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), true)6315+ t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(t.layout), true)6316 case reqReinit, reqResize, reqFullRedraw, reqRedraw:6317 if req == reqReinit {6318 t.tui.Resume(t.fullscreen, true)6319 }1324 unmodified lines7644 pborderDragging = 07645 } else if t.listBorderShape.HasRight() && t.pborder.EncloseY(my) && mx == t.wborder.Left()+t.wborder.Width()-1 {7646 pborderDragging = 17647 }7648+ case posNext:7649+ if t.layout == layoutReverse {7650+ if t.pborder.Enclose(my, mx) && my == t.pborder.Top()+t.pborder.Height()-1 {7651+ pborderDragging = 07652+ } else if t.listBorderShape.HasTop() && t.pborder.EncloseX(mx) && my == t.wborder.Top() {7653+ pborderDragging = 17654+ }7655+ } else {7656+ if t.pborder.Enclose(my, mx) && my == t.pborder.Top() {7657+ pborderDragging = 07658+ } else if t.listBorderShape.HasBottom() && t.pborder.EncloseX(mx) && my == t.wborder.Top()+t.wborder.Height()-1 {7659+ pborderDragging = 17660+ }7661+ }7662 }7663 }7664 7665 if t.hasPreviewWindow() && pborderDragging >= 0 {15 unmodified lines7681 case posRight:7682 prevSize = t.pwindow.Width()7683 offset := mx - t.pborder.Left()7684 newSize = prevSize - offset7685+ case posNext:7686+ prevSize = t.pwindow.Height()7687+ // In posNext, header/header-lines sections may sit7688+ // between preview and list. When the list border is7689+ // dragged (pborderDragging == 1), subtract that gap7690+ // so the initial click does not jump.7691+ headerGap := 07692+ if pborderDragging == 1 && t.wborder != nil {7693+ if t.layout == layoutReverse {7694+ headerGap = t.wborder.Top() - (t.pborder.Top() + t.pborder.Height())7695+ } else {7696+ headerGap = t.pborder.Top() - (t.wborder.Top() + t.wborder.Height())7697+ }7698+ }7699+ if t.layout == layoutReverse {7700+ diff := t.pborder.Height() - prevSize7701+ newSize = my - t.pborder.Top() - diff + 1 - headerGap7702+ } else {7703+ offset := my - t.pborder.Top()7704+ newSize = prevSize - offset - headerGap7705+ }7706 }7707 newSize -= pborderDragging7708 if newSize < 1 {7709 newSize = 1124 unmodified lines7834 }7835 7836 if me.Down {7837 mxCons := util.Constrain(mx-t.promptLen, 0, len(t.input))7743- if !t.inputless && t.inputWindow == nil && my == t.promptLine() && mxCons >= 0 {7838+ if !t.inputless && t.inputWindow == nil && my == 0 && mxCons >= 0 {7839 // Prompt7840 t.cx = mxCons + t.xoffset7841 } else if my >= min {7842 t.vset(cy)517 unmodified linesmodified:test/test_layout.rb+175 added-60 removed
241 unmodified lines242 OUTPUT243 tmux.until { assert_block(expected, it) }244 end245 246+ def test_preview_window_next_reverse247+ # https://github.com/junegunn/fzf/issues/4798248+ tmux.send_keys %(seq 5 | #{FZF} --layout=reverse --preview 'echo PREVIEW' --preview-window=next:3 --prompt='line2$ > '), :Enter249+ expected = <<~OUTPUT250+ line2$ >251+ 5/5 ───252+ ╭────────253+ │ PREVIEW254+ │255+ │256+ ╰────────257+ > 1258+ OUTPUT259+ tmux.until { assert_block(expected, it) }260+ end261+262+ def test_preview_window_next_default263+ tmux.send_keys %(seq 5 | #{FZF} --preview 'echo PREVIEW' --preview-window=next:3), :Enter264+ expected = <<~OUTPUT265+ > 1266+ ╭────────267+ │ PREVIEW268+ │269+ │270+ ╰────────271+ 5/5 ───272+ >273+ OUTPUT274+ tmux.until { assert_block(expected, it) }275+ end276+277+ def test_preview_window_next_border_line_at_runtime278+ # change-preview-window to next,border-line should resolve BorderLine279+ # to a single horizontal separator, matching the behavior280+ # when next,border-line is the initial spec.281+ tmux.send_keys %(seq 5 | #{FZF} --preview 'echo PREVIEW' --bind 'space:change-preview-window:next:3,border-line'), :Enter282+ tmux.until { |lines| assert_equal 5, lines.match_count }283+ tmux.send_keys :Space284+ expected = <<~OUTPUT285+ > 1286+ ───────287+ PREVIEW288+ OUTPUT289+ tmux.until do |lines|290+ cursor = lines.index { it.start_with?('> 1') }291+ assert(cursor)292+ assert_block(expected, lines[cursor..])293+ end294+ end295+296+ def test_header_first_change_header_at_runtime297+ # --header-first with no initial --header content needs to grow a298+ # header window when change-header adds content at runtime, so the299+ # new header lands below the prompt (not on top of it).300+ tmux.send_keys %(seq 5 | #{FZF} --header-first --bind 'space:change-header:foo'), :Enter301+ tmux.until { |lines| assert_equal 5, lines.match_count }302+ tmux.send_keys :Space303+ expected = <<~OUTPUT304+ >305+ foo306+ OUTPUT307+ tmux.until do |lines|308+ prompt = lines.index { it.start_with?('>') }309+ assert(prompt)310+ assert_block(expected, lines[prompt..])311+ end312+ end313+314+ def test_preview_window_next_style_full_line315+ tmux.send_keys %(seq 5 | #{FZF} --reverse --preview 'echo PREVIEW' --preview-window=next:3 --header foo --footer bar --style full:line), :Enter316+ expected = <<~OUTPUT317+ >318+ ───────319+ PREVIEW320+321+322+ ───────323+ foo324+ ───────325+ > 1326+ OUTPUT327+ tmux.until { assert_block(expected, it) }328+ end329+330 def test_height_range_overflow331 tmux.send_keys 'seq 100 | fzf --height ~5 --info=inline --border rounded', :Enter332 expected = <<~OUTPUT333 ╭──────────────976 unmodified lines1310 1311 def test_combinations1312 skip unless ENV['LONGTEST']1313 1230- base = [1231- '--pointer=@',1232- '--exact',1233- '--query=123',1234- '--header="$(seq 101 103)"',1235- '--header-lines=3',1236- '--footer "$(seq 201 203)"',1237- '--preview "echo foobar"'1238- ]1239- options = [1240- ['--separator==', '--no-separator'],1241- ['--info=default', '--info=inline', '--info=inline-right'],1242- ['--no-input-border', '--input-border'],1243- ['--no-header-border', '--header-border=none', '--header-border'],1244- ['--no-header-lines-border', '--header-lines-border'],1245- ['--no-footer-border', '--footer-border'],1246- ['--no-list-border', '--list-border'],1247- ['--preview-window=right', '--preview-window=up', '--preview-window=down', '--preview-window=left'],1248- ['--header-first', '--no-header-first'],1249- ['--layout=default', '--layout=reverse', '--layout=reverse-list']1250- ]1251- # Combination of all options1252- combinations = options[0].product(*options.drop(1))1253- combinations.each_with_index do |combination, index|1254- opts = base + combination1255- command = %(seq 1001 2000 | #{FZF} #{opts.join(' ')})1256- puts "# #{index + 1}/#{combinations.length}\n#{command}"1257- tmux.send_keys command, :Enter1258- tmux.until do |lines|1259- layout = combination.find { it.start_with?('--layout=') }.split('=').last1260- header_first = combination.include?('--header-first')1314+ begin1315+ base = [1316+ '--pointer=@',1317+ '--exact',1318+ '--query=123',1319+ '--header="$(seq 101 103)"',1320+ '--header-lines=3',1321+ '--footer "$(seq 201 203)"',1322+ '--preview "echo foobar"'1323+ ]1324+ options = [1325+ ['--separator==', '--no-separator'],1326+ ['--info=default', '--info=inline', '--info=inline-right'],1327+ ['--no-input-border', '--input-border'],1328+ ['--no-header-border', '--header-border=none', '--header-border'],1329+ ['--no-header-lines-border', '--header-lines-border'],1330+ ['--no-footer-border', '--footer-border'],1331+ ['--no-list-border', '--list-border'],1332+ ['--preview-window=right', '--preview-window=up', '--preview-window=down', '--preview-window=left', '--preview-window=next'],1333+ ['--header-first', '--no-header-first'],1334+ ['--layout=default', '--layout=reverse', '--layout=reverse-list']1335+ ]1336+ # Combination of all options1337+ combinations = options[0].product(*options.drop(1))1338 1262- # Input1263- input = lines.index { it.include?('> 123') }1264- assert(input)1339+ # Run workers in parallel, each with its own pre-created tmux window.1340+ # Tmux setup/teardown is serialized in the main thread to avoid racing1341+ # `tmux new-window` and `tmux kill-window` calls on the tmux server.1342+ workers = 101343+ tmuxes = Array.new(workers) { Tmux.new }1344+ failures = []1345+ mutex = Mutex.new1346+ queue = Queue.new1347+ index = 01348+ threads = tmuxes.map do |local_tmux|1349+ Thread.new do1350+ command = nil1351+ loop do1352+ combination = queue.pop or break1353 1266- # Info1267- info = lines.index { it.include?('11/997') }1268- assert(info)1354+ opts = base + combination1355+ command = %(seq 1001 2000 | #{FZF} #{opts.join(' ')})1356+ mutex.synchronize do1357+ print("\r#{index += 1}/#{combinations.length}")1358+ end1359+ local_tmux.send_keys command, :Enter1360+ local_tmux.until do |lines|1361+ layout = combination.find { it.start_with?('--layout=') }.split('=').last1362+ header_first = combination.include?('--header-first')1363 1270- assert(layout == 'reverse' ? input <= info : input >= info)1364+ # Input1365+ input = lines.index { it.include?('> 123') }1366+ assert(input)1367 1272- # List1273- item1 = lines.index { it.include?('1230') }1274- item2 = lines.index { it.include?('1231') }1275- assert_equal(item1, layout == 'default' ? item2 + 1 : item2 - 1)1368+ # Info1369+ info = lines.index { it.include?('11/997') }1370+ assert(info)1371 1277- # Preview1278- assert(lines.any? { it.include?('foobar') })1372+ assert(layout == 'reverse' ? input <= info : input >= info)1373 1280- # Header1281- header1 = lines.index { it.include?('101') }1282- header2 = lines.index { it.include?('102') }1283- assert_equal(header2, header1 + 1)1284- assert((layout == 'reverse') == header_first ? input > header1 : input < header1)1374+ # List1375+ item1 = lines.index { it.include?('1230') }1376+ item2 = lines.index { it.include?('1231') }1377+ assert_equal(item1, layout == 'default' ? item2 + 1 : item2 - 1)1378 1286- # Footer1287- footer1 = lines.index { it.include?('201') }1288- footer2 = lines.index { it.include?('202') }1289- assert_equal(footer2, footer1 + 1)1290- assert(layout == 'reverse' ? footer1 > item2 : footer1 < item2)1379+ # Preview1380+ assert(lines.any? { it.include?('foobar') })1381 1382+ # Header1383+ header1 = lines.index { it.include?('101') }1384+ header2 = lines.index { it.include?('102') }1385+ assert_equal(header2, header1 + 1)1386+ assert((layout == 'reverse') == header_first ? input > header1 : input < header1)1387+1388+ # Footer1389+ footer1 = lines.index { it.include?('201') }1390+ footer2 = lines.index { it.include?('202') }1391+ assert_equal(footer2, footer1 + 1)1392+ assert(layout == 'reverse' ? footer1 > item2 : footer1 < item2)1393+1292- # Header lines1293- hline1 = lines.index { it.include?('1001') }1294- hline2 = lines.index { it.include?('1002') }1295- assert_equal(hline1, layout == 'default' ? hline2 + 1 : hline2 - 1)1296- assert(layout == 'reverse' ? hline1 > header1 : hline1 < header1)1394+ # Header lines1395+ hline1 = lines.index { it.include?('1001') }1396+ hline2 = lines.index { it.include?('1002') }1397+ assert_equal(hline1, layout == 'default' ? hline2 + 1 : hline2 - 1)1398+ assert(layout == 'reverse' ? hline1 > header1 : hline1 < header1)1399+ end1400+ local_tmux.send_keys :Enter1401+ end1402+ rescue StandardError, Minitest::Assertion => e1403+ mutex.synchronize { failures << [command, e] }1404+ end1405 end1298- tmux.send_keys :Enter1406+ combinations.each { queue << it }1407+ queue.close1408+1409+ threads.each(&:join)1410+ raise failures.inspect unless failures.empty?1411+ ensure1412+ # Reverse so any tmux window renumbering does not leave stale indices behind.1413+ tmuxes&.reverse_each(&:kill)1414 end1415 end1416 1417 # Locate a word in the currently captured screen and click its first character.332 unmodified linesmodified:CHANGELOG.md+1 added
14 unmodified lines15 elif [[ $FZF_IDLE_TIME -lt 10 ]]; then echo "change-footer:auto-accept in $((10 - FZF_IDLE_TIME))s"16 else echo accept17 fi'18 ```19+- New `--preview-window=next` position that places the preview adjacent to the input section, on the list side: above the input in the default layout, below it in `--layout=reverse` (#4798).20 - Bug fixes21 - `change-preview-window` no longer resets `wrap` / `wrap-word` state set via `toggle-preview-wrap` / `toggle-preview-wrap-word`. Layout fields still snap to the preset, so cycling and the empty-token reset behave as before. The new spec can still override by including `wrap` or `nowrap` explicitly. (#4791)22 23 0.72.03282 unmodified lines