Always check hasPreviewWindow() before processing preview mouse events

This commit is contained in:
Junegunn Choi
2026-03-22 10:09:57 +09:00
parent 95f186f364
commit 6153004070
+7 -5
View File
@@ -7184,10 +7184,12 @@ func (t *Terminal) Loop() error {
} }
if !me.Down { if !me.Down {
barDragging = false barDragging = false
pmx, pmy = -1, -1
}
if !me.Down || !t.hasPreviewWindow() {
pbarDragging = false pbarDragging = false
pborderDragging = -1 pborderDragging = -1
previewDraggingPos = -1 previewDraggingPos = -1
pmx, pmy = -1, -1
} }
// Scrolling // Scrolling
@@ -7215,7 +7217,7 @@ func (t *Terminal) Loop() error {
} }
// Preview dragging // Preview dragging
if me.Down && (previewDraggingPos >= 0 || click && t.hasPreviewWindow() && t.pwindow.Enclose(my, mx)) { if t.hasPreviewWindow() && me.Down && (previewDraggingPos >= 0 || click && t.pwindow.Enclose(my, mx)) {
if previewDraggingPos > 0 { if previewDraggingPos > 0 {
scrollPreviewBy(previewDraggingPos - my) scrollPreviewBy(previewDraggingPos - my)
} }
@@ -7225,7 +7227,7 @@ func (t *Terminal) Loop() error {
// Preview scrollbar dragging // Preview scrollbar dragging
headerLines := t.activePreviewOpts.headerLines headerLines := t.activePreviewOpts.headerLines
pbarDragging = me.Down && (pbarDragging || click && t.hasPreviewWindow() && my >= t.pwindow.Top()+headerLines && my < t.pwindow.Top()+t.pwindow.Height() && mx == t.pwindow.Left()+t.pwindow.Width()) pbarDragging = t.hasPreviewWindow() && me.Down && (pbarDragging || click && my >= t.pwindow.Top()+headerLines && my < t.pwindow.Top()+t.pwindow.Height() && mx == t.pwindow.Left()+t.pwindow.Width())
if pbarDragging { if pbarDragging {
effectiveHeight := t.pwindow.Height() - headerLines effectiveHeight := t.pwindow.Height() - headerLines
numLines := len(t.previewer.lines) - headerLines numLines := len(t.previewer.lines) - headerLines
@@ -7242,7 +7244,7 @@ func (t *Terminal) Loop() error {
} }
// Preview border dragging (resizing) // Preview border dragging (resizing)
if pborderDragging < 0 && click && t.hasPreviewWindow() { if t.hasPreviewWindow() && pborderDragging < 0 && click {
switch t.activePreviewOpts.position { switch t.activePreviewOpts.position {
case posUp: case posUp:
if t.pborder.Enclose(my, mx) && my == t.pborder.Top()+t.pborder.Height()-1 { if t.pborder.Enclose(my, mx) && my == t.pborder.Top()+t.pborder.Height()-1 {
@@ -7271,7 +7273,7 @@ func (t *Terminal) Loop() error {
} }
} }
if pborderDragging >= 0 && t.hasPreviewWindow() { if t.hasPreviewWindow() && pborderDragging >= 0 {
var newSize int var newSize int
var prevSize int var prevSize int
switch t.activePreviewOpts.position { switch t.activePreviewOpts.position {