mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-10 09:02:01 -07:00
Allow dragging of the preview window
This commit is contained in:
@@ -2588,7 +2588,9 @@ func (t *Terminal) Loop() {
|
|||||||
t.eventChan <- t.tui.GetChar()
|
t.eventChan <- t.tui.GetChar()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
dragging := false
|
previewDraggingPos := -1
|
||||||
|
barDragging := false
|
||||||
|
wasDown := false
|
||||||
for looping {
|
for looping {
|
||||||
var newCommand *string
|
var newCommand *string
|
||||||
var reloadSync bool
|
var reloadSync bool
|
||||||
@@ -3032,8 +3034,15 @@ func (t *Terminal) Loop() {
|
|||||||
case actMouse:
|
case actMouse:
|
||||||
me := event.MouseEvent
|
me := event.MouseEvent
|
||||||
mx, my := me.X, me.Y
|
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 {
|
if me.S != 0 {
|
||||||
// Scroll
|
|
||||||
if t.window.Enclose(my, mx) && t.merger.Length() > 0 {
|
if t.window.Enclose(my, mx) && t.merger.Length() > 0 {
|
||||||
if t.multi > 0 && me.Mod {
|
if t.multi > 0 && me.Mod {
|
||||||
toggle()
|
toggle()
|
||||||
@@ -3043,7 +3052,24 @@ func (t *Terminal) Loop() {
|
|||||||
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
|
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
|
||||||
scrollPreviewBy(-me.S)
|
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()
|
mx -= t.window.Left()
|
||||||
my -= t.window.Top()
|
my -= t.window.Top()
|
||||||
min := 2 + len(t.header)
|
min := 2 + len(t.header)
|
||||||
@@ -3061,15 +3087,10 @@ func (t *Terminal) Loop() {
|
|||||||
my = h - my - 1
|
my = h - my - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dragging = me.Down && (dragging || my >= min && mx == t.window.Width()-1)
|
|
||||||
if me.Double {
|
// Scrollbar dragging
|
||||||
// Double-click
|
barDragging = me.Down && (barDragging || clicked && my >= min && mx == t.window.Width()-1)
|
||||||
if my >= min {
|
if barDragging {
|
||||||
if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
|
|
||||||
return doActions(actionsFor(tui.DoubleClick))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if dragging && my >= min {
|
|
||||||
barLength, barStart := t.getScrollbar()
|
barLength, barStart := t.getScrollbar()
|
||||||
if barLength > 0 {
|
if barLength > 0 {
|
||||||
maxItems := t.maxItems()
|
maxItems := t.maxItems()
|
||||||
@@ -3082,7 +3103,21 @@ func (t *Terminal) Loop() {
|
|||||||
req(reqList)
|
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))
|
mx = util.Constrain(mx-t.promptLen, 0, len(t.input))
|
||||||
if my == t.promptLine() && mx >= 0 {
|
if my == t.promptLine() && mx >= 0 {
|
||||||
// Prompt
|
// Prompt
|
||||||
@@ -3099,7 +3134,6 @@ func (t *Terminal) Loop() {
|
|||||||
return doActions(actionsFor(tui.RightClick))
|
return doActions(actionsFor(tui.RightClick))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case actReload, actReloadSync:
|
case actReload, actReloadSync:
|
||||||
t.failed = nil
|
t.failed = nil
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user