diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-12-08 20:03:15 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-12-12 13:53:08 +0900 |
| commit | da9179335c637d91ab49256dd3c3e7dcdf319e19 (patch) | |
| tree | eb0fff56ab0404aec4a75125b96bcb8913ce4fae /src/options.go | |
| parent | cdf641fa3ef266fee7217bf01513e5f942adb340 (diff) | |
| download | fzf-da9179335c637d91ab49256dd3c3e7dcdf319e19.tar.gz | |
Respect the properties of the currently active preview window options
Diffstat (limited to 'src/options.go')
| -rw-r--r-- | src/options.go | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/options.go b/src/options.go index 9238ac69..b4df2c17 100644 --- a/src/options.go +++ b/src/options.go @@ -381,14 +381,46 @@ func (a previewOpts) aboveOrBelow() bool { return a.size.size > 0 && (a.position == posUp || a.position == posDown) } -func (a previewOpts) sameLayout(b previewOpts) bool { - return a.size == b.size && a.position == b.position && a.border == b.border && a.hidden == b.hidden && a.threshold == b.threshold && - (a.alternative != nil && b.alternative != nil && a.alternative.sameLayout(*b.alternative) || - a.alternative == nil && b.alternative == nil) -} +type previewOptsCompare int + +const ( + previewOptsSame previewOptsCompare = iota + previewOptsDifferentContentLayout + previewOptsDifferentLayout +) + +func (o *previewOpts) compare(active *previewOpts, b *previewOpts) previewOptsCompare { + a := o + + sameThreshold := o.position == b.position && o.threshold == b.threshold + // Alternative layout is being used + if o.alternative == active { + a = active + + // If the other also has an alternative layout, + if b.alternative != nil { + // and if the same condition is the same, compare alt vs. alt. + if sameThreshold { + b = b.alternative + } else { + // If not, we pessimistically decide that the layouts may not be the same + return previewOptsDifferentLayout + } + } + } else if b.alternative != nil && !sameThreshold { + // We may choose the other's alternative layout, so let's be conservative. + return previewOptsDifferentLayout + } + + if !(a.size == b.size && a.position == b.position && a.border == b.border && a.hidden == b.hidden) { + return previewOptsDifferentLayout + } + + if a.wrap == b.wrap && a.headerLines == b.headerLines && a.info == b.info && a.scroll == b.scroll { + return previewOptsSame + } -func (a previewOpts) sameContentLayout(b previewOpts) bool { - return a.wrap == b.wrap && a.headerLines == b.headerLines && a.info == b.info + return previewOptsDifferentContentLayout } func firstLine(s string) string { |
