summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-12-10 21:01:46 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-12-12 13:53:08 +0900
commit6c6be4ab1a662328ff97bac6427fbb212a3f840b (patch)
tree6c9338745f72d676160b979fe8221c459cf28963 /src
parentd004eb1f7cb5d62e0c5e4d33cce5d5ad4e02023e (diff)
downloadfzf-6c6be4ab1a662328ff97bac6427fbb212a3f840b.tar.gz
Simplify resize code
Diffstat (limited to 'src')
-rw-r--r--src/terminal.go53
1 files changed, 16 insertions, 37 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 138617e2..86a48c51 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -1692,13 +1692,13 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)
} else {
- t.window = t.tui.NewWindow(
- marginInt[0], marginInt[3], width-pwidth, height, false, noBorder)
// NOTE: fzf --preview 'cat {}' --preview-window border-left --border
- x := marginInt[3] + width - pwidth
if !previewOpts.border.HasRight() && t.borderShape.HasRight() {
- pwidth++
+ width++
}
+ t.window = t.tui.NewWindow(
+ marginInt[0], marginInt[3], width-pwidth, height, false, noBorder)
+ x := marginInt[3] + width - pwidth
createPreviewWindow(marginInt[0], x, pwidth, height)
}
}
@@ -4740,49 +4740,28 @@ func (t *Terminal) Loop() error {
pborderDragging = mx == t.pborder.Left()
}
}
- if pborderDragging {
- previewWidth := t.pwindow.Width() + borderColumns(t.activePreviewOpts.border, t.borderWidth)
- previewHeight := t.pwindow.Height() + borderLines(t.activePreviewOpts.border)
- minPreviewWidth, minPreviewHeight := t.minPreviewSize(t.activePreviewOpts)
-
- // Decrement, so the cursor drags the last column/row of the
- // preview window (i.e. in most cases the border) and not
- // the one after.
- minPreviewWidth--
- minPreviewHeight--
-
- previewLeft := t.pwindow.Left()
- previewTop := t.pwindow.Top()
- // pwindow does not include it's border, so Left and Top have to be adjusted.
- if t.activePreviewOpts.border.HasLeft() {
- previewLeft -= 1 + t.borderWidth
- }
- if t.activePreviewOpts.border.HasTop() {
- previewTop -= 1
- }
+ if pborderDragging {
var newSize int
switch t.activePreviewOpts.position {
+ case posLeft:
+ diff := t.pborder.Width() - t.pwindow.Width()
+ newSize = mx - t.pborder.Left() - diff + 1
case posUp:
- top := previewTop + minPreviewHeight
- // +1 since index to size
- newSize = my - top + 1
- case posRight:
- right := previewLeft + previewWidth - minPreviewWidth
- newSize = right - mx
+ diff := t.pborder.Height() - t.pwindow.Height()
+ newSize = my - t.pborder.Top() - diff + 1
case posDown:
- bottom := previewTop + previewHeight - minPreviewHeight
- newSize = bottom - my
- case posLeft:
- left := previewLeft + minPreviewWidth
- // +1 since index to size
- newSize = mx - left + 1
+ offset := my - t.pborder.Top()
+ newSize = t.pwindow.Height() - offset
+ case posRight:
+ offset := mx - t.pborder.Left()
+ newSize = t.pwindow.Width() - offset
}
if newSize < 1 {
newSize = 1
}
- // don't update if the size did not change (e.g. off-axis movement)
+ // Don't update if the size did not change (e.g. off-axis movement)
if !t.activePreviewOpts.size.percent && t.activePreviewOpts.size.size == float64(newSize) {
break
}