Allow dragging of the preview window

pull/3111/head
Junegunn Choi 1 year ago
parent 1fc1f47d80
commit c1cd0c09a2
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -2588,7 +2588,9 @@ func (t *Terminal) Loop() {
t.eventChan <- t.tui.GetChar()
}
}()
dragging := false
previewDraggingPos := -1
barDragging := false
wasDown := false
for looping {
var newCommand *string
var reloadSync bool
@ -3032,8 +3034,15 @@ func (t *Terminal) Loop() {
case actMouse:
me := event.MouseEvent
mx, my := me.X, me.Y
clicked := !wasDown && me.Down
wasDown = me.Down
if !me.Down {
barDragging = false
previewDraggingPos = -1
}
// Scrolling
if me.S != 0 {
// Scroll
if t.window.Enclose(my, mx) && t.merger.Length() > 0 {
if t.multi > 0 && me.Mod {
toggle()
@ -3043,7 +3052,24 @@ func (t *Terminal) Loop() {
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
scrollPreviewBy(-me.S)
}
} else if t.window.Enclose(my, mx) {
break
}
// Preview dragging
if me.Down && (previewDraggingPos > 0 || clicked && t.hasPreviewWindow() && t.pwindow.Enclose(my, mx)) {
if previewDraggingPos > 0 {
scrollPreviewBy(previewDraggingPos - my)
}
previewDraggingPos = my
break
}
// Ignored
if !t.window.Enclose(my, mx) && !barDragging {
break
}
// Translate coordinates
mx -= t.window.Left()
my -= t.window.Top()
min := 2 + len(t.header)
@ -3061,15 +3087,10 @@ func (t *Terminal) Loop() {
my = h - my - 1
}
}
dragging = me.Down && (dragging || my >= min && mx == t.window.Width()-1)
if me.Double {
// Double-click
if my >= min {
if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
return doActions(actionsFor(tui.DoubleClick))
}
}
} else if dragging && my >= min {
// Scrollbar dragging
barDragging = me.Down && (barDragging || clicked && my >= min && mx == t.window.Width()-1)
if barDragging {
barLength, barStart := t.getScrollbar()
if barLength > 0 {
maxItems := t.maxItems()
@ -3082,7 +3103,21 @@ func (t *Terminal) Loop() {
req(reqList)
}
}
} else if me.Down {
break
}
// Double-click on an item
if me.Double && mx < t.window.Width()-1 {
// Double-click
if my >= min {
if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
return doActions(actionsFor(tui.DoubleClick))
}
}
break
}
if me.Down {
mx = util.Constrain(mx-t.promptLen, 0, len(t.input))
if my == t.promptLine() && mx >= 0 {
// Prompt
@ -3099,7 +3134,6 @@ func (t *Terminal) Loop() {
return doActions(actionsFor(tui.RightClick))
}
}
}
case actReload, actReloadSync:
t.failed = nil

Loading…
Cancel
Save