Skip to content
Myr

Make the preview window resizable by mouse drag

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Enable resizing the preview window by dragging its border with the mouse. This works with all border styles except for `none`. Counter-intuitively, having the border only on the opposite side of the window works too - dragging from it will first decrease the preview size to its minimum.

authored by Julian Prein · committed by Junegunn Choi · parent bb55045 · Browse files · 1 file+76 added−0 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+76 added−0 removed

  • other:+76 added−0 removed

1 file+76 added−0 removed

modified:src/terminal.go+76 added
1002 unmodified lines
1003 }1004 return 01005}10061007func borderColumns(shape tui.BorderShape, borderWidth int) int {1008 columns := 01009 if shape.HasLeft() {1010 columns += 1 + borderWidth1011 }1012 if shape.HasRight() {1013 columns += 1 + borderWidth1014 }1015 return columns1016}10171018func (t *Terminal) visibleHeaderLines() int {1019 if !t.headerVisible {1020 return 01021 }
2941 unmodified lines
3963 }()3964 previewDraggingPos := -13965 barDragging := false3966 pbarDragging := false3967 pborderDragging := false3968 wasDown := false3969 needBarrier := true39703971 // If an action is bound to 'start', we're going to process it before reading
715 unmodified lines
4687 wasDown = me.Down4688 if !me.Down {4689 barDragging = false4690 pbarDragging = false4691 pborderDragging = false4692 previewDraggingPos = -14693 }46944695 // Scrolling
46 unmodified lines
4742 }4743 break4744 }47454746 // Preview border dragging (resizing)4747 pborderDragging = me.Down && (pborderDragging || clicked && t.hasPreviewWindow() && t.pborder.Enclose(my, mx))4748 if pborderDragging {4749 previewWidth := t.pwindow.Width() + borderColumns(t.previewOpts.border, t.borderWidth)4750 previewHeight := t.pwindow.Height() + borderLines(t.previewOpts.border)4751 minPreviewWidth := 1 + borderColumns(t.previewOpts.border, t.borderWidth)4752 minPreviewHeight := 1 + borderLines(t.previewOpts.border)47534754 if len(t.scrollbar) > 0 && t.previewOpts.position == posLeft && !t.previewOpts.border.HasRight() {4755 // Need a column to show scrollbar4756 minPreviewWidth++4757 }47584759 // Decrement, so the cursor drags the last column/row of the4760 // preview window (i.e. in most cases the border) and not4761 // the one after.4762 minPreviewWidth--4763 minPreviewHeight--47644765 previewLeft := t.pwindow.Left()4766 previewTop := t.pwindow.Top()4767 // Unlike window, pwindow does not include it's border, so4768 // Left and Top have to be adjusted.4769 if t.previewOpts.border.HasLeft() {4770 previewLeft -= 1 + t.borderWidth4771 }4772 if t.previewOpts.border.HasTop() {4773 previewTop -= 14774 }47754776 var newSize int4777 switch t.previewOpts.position {4778 case posUp:4779 top := previewTop + minPreviewHeight4780 // +1 since index to size4781 newSize = my - top + 14782 case posRight:4783 right := previewLeft + previewWidth - minPreviewWidth4784 newSize = right - mx4785 case posDown:4786 bottom := previewTop + previewHeight - minPreviewHeight4787 newSize = bottom - my4788 case posLeft:4789 left := previewLeft + minPreviewWidth4790 // +1 since index to size4791 newSize = mx - left + 14792 }4793 // TODO: should this allow a size of zero?4794 if newSize < 1 {4795 newSize = 14796 }47974798 // don't update if the size did not change (e.g. off-axis movement)4799 if !t.previewOpts.size.percent && t.previewOpts.size.size == float64(newSize) {4800 break4801 }48024803 t.previewOpts.size = sizeSpec{float64(newSize), false}4804 updatePreviewWindow(false)4805 req(reqPreviewRefresh)4806 break4807 }48084809 // Ignored4810 if !t.window.Enclose(my, mx) && !barDragging {4811 break4812 }
480 unmodified lines