Simplify resize code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent d004eb1 · Browse files · 1 file·+16 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+16 added−37 removed
- other:+16 added−37 removed
Provenance
- Commit
6c6be4a- Tree
6c93387- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
d004eb1
1 file changed+16 added−37 removed
modified:src/terminal.go+16 added-37 removed
1690 unmodified lines1691 }1692 1693 createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)1694 } else {1695- t.window = t.tui.NewWindow(1696- marginInt[0], marginInt[3], width-pwidth, height, false, noBorder)1695 // NOTE: fzf --preview 'cat {}' --preview-window border-left --border1698- x := marginInt[3] + width - pwidth1696 if !previewOpts.border.HasRight() && t.borderShape.HasRight() {1700- pwidth++1697+ width++1698 }1699+ t.window = t.tui.NewWindow(1700+ marginInt[0], marginInt[3], width-pwidth, height, false, noBorder)1701+ x := marginInt[3] + width - pwidth1702 createPreviewWindow(marginInt[0], x, pwidth, height)1703 }1704 }1705 }3033 unmodified lines4739 case posRight:4740 pborderDragging = mx == t.pborder.Left()4741 }4742 }4743- if pborderDragging {4744- previewWidth := t.pwindow.Width() + borderColumns(t.activePreviewOpts.border, t.borderWidth)4745- previewHeight := t.pwindow.Height() + borderLines(t.activePreviewOpts.border)4746- minPreviewWidth, minPreviewHeight := t.minPreviewSize(t.activePreviewOpts)4743 4748- // Decrement, so the cursor drags the last column/row of the4749- // preview window (i.e. in most cases the border) and not4750- // the one after.4751- minPreviewWidth--4752- minPreviewHeight--4753-4754- previewLeft := t.pwindow.Left()4755- previewTop := t.pwindow.Top()4756- // pwindow does not include it's border, so Left and Top have to be adjusted.4757- if t.activePreviewOpts.border.HasLeft() {4758- previewLeft -= 1 + t.borderWidth4759- }4760- if t.activePreviewOpts.border.HasTop() {4761- previewTop -= 14762- }4763-4744+ if pborderDragging {4745 var newSize int4746 switch t.activePreviewOpts.position {4747+ case posLeft:4748+ diff := t.pborder.Width() - t.pwindow.Width()4749+ newSize = mx - t.pborder.Left() - diff + 14750 case posUp:4767- top := previewTop + minPreviewHeight4768- // +1 since index to size4769- newSize = my - top + 14770- case posRight:4771- right := previewLeft + previewWidth - minPreviewWidth4772- newSize = right - mx4751+ diff := t.pborder.Height() - t.pwindow.Height()4752+ newSize = my - t.pborder.Top() - diff + 14753 case posDown:4774- bottom := previewTop + previewHeight - minPreviewHeight4775- newSize = bottom - my4776- case posLeft:4777- left := previewLeft + minPreviewWidth4778- // +1 since index to size4779- newSize = mx - left + 14754+ offset := my - t.pborder.Top()4755+ newSize = t.pwindow.Height() - offset4756+ case posRight:4757+ offset := mx - t.pborder.Left()4758+ newSize = t.pwindow.Width() - offset4759 }4760 if newSize < 1 {4761 newSize = 14762 }4763 4785- // don't update if the size did not change (e.g. off-axis movement)4764+ // Don't update if the size did not change (e.g. off-axis movement)4765 if !t.activePreviewOpts.size.percent && t.activePreviewOpts.size.size == float64(newSize) {4766 break4767 }4768 492 unmodified lines