1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

bump gocui

This commit is contained in:
Jesse Duffield 2021-02-09 21:49:03 +11:00
parent c0cad91cb6
commit 6472bda29e
4 changed files with 56 additions and 18 deletions

View File

@ -1357,14 +1357,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone,
Handler: gui.handleLBLMouseDown,
},
// TODO: see how to get mouse dragging in tcell
// {
// ViewName: "main",
// Contexts: []string{MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY},
// Key: gocui.MouseLeft,
// Modifier: gocui.ModMotion,
// Handler: gui.handleMouseDrag,
// },
{
ViewName: "main",
Contexts: []string{MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY},
Key: gocui.MouseLeft,
Modifier: gocui.ModMotion,
Handler: gui.handleMouseDrag,
},
{
ViewName: "main",
Contexts: []string{MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY},

View File

@ -356,17 +356,18 @@ func (v *View) writeRune(x, y int, ch rune) error {
}
olen := len(v.lines[y])
w := runewidth.RuneWidth(ch)
var s []cell
if x >= len(v.lines[y]) {
s = make([]cell, x-len(v.lines[y])+1)
s = make([]cell, x-len(v.lines[y])+w)
} else if !v.Overwrite {
s = make([]cell, 1)
s = make([]cell, w)
}
v.lines[y] = append(v.lines[y], s...)
if !v.Overwrite || (v.Overwrite && x >= olen-1) {
copy(v.lines[y][x+1:], v.lines[y][x:])
if !v.Overwrite || (v.Overwrite && x >= olen-w) {
copy(v.lines[y][x+w:], v.lines[y][x:])
}
v.lines[y][x] = cell{
fgColor: v.FgColor,
@ -374,6 +375,14 @@ func (v *View) writeRune(x, y int, ch rune) error {
chr: ch,
}
for i := 1; i < w; i++ {
v.lines[y][x+i] = cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: '\x00',
}
}
return nil
}
@ -400,7 +409,7 @@ func (v *View) deleteRune(x, y int) (int, error) {
w := runewidth.RuneWidth(v.lines[y][i].chr)
tw += w
if tw > x {
v.lines[y] = append(v.lines[y][:i], v.lines[y][i+1:]...)
v.lines[y] = append(v.lines[y][:i], v.lines[y][i+w:]...)
return w, nil
}

View File

@ -317,8 +317,9 @@ const (
// Modifiers.
const (
ModNone Modifier = Modifier(0)
ModAlt = Modifier(tcell.ModAlt)
ModNone Modifier = Modifier(0)
ModAlt = Modifier(tcell.ModAlt)
ModMotion = Modifier(2) // just picking an arbitrary number here that doesn't clash with tcell.ModAlt
// ModCtrl doesn't work with keyboard keys. Use CtrlKey in Key and ModNone. This is was for mouse clicks only (tcell.v1)
// ModCtrl = Modifier(tcell.ModCtrl)
)

View File

@ -104,9 +104,18 @@ const (
eventRaw
)
const (
NOT_DRAGGING int = iota
MAYBE_DRAGGING
DRAGGING
)
var (
lastMouseKey tcell.ButtonMask = tcell.ButtonNone
lastMouseMod tcell.ModMask = tcell.ModNone
dragState int = NOT_DRAGGING
lastX int = 0
lastY int = 0
)
// pollEvent get tcell.Event and transform it into gocuiEvent
@ -172,6 +181,17 @@ func pollEvent() GocuiEvent {
if button != tcell.ButtonNone && lastMouseKey == tcell.ButtonNone {
lastMouseKey = button
lastMouseMod = tev.Modifiers()
switch button {
case tcell.ButtonPrimary:
mouseKey = MouseLeft
dragState = MAYBE_DRAGGING
lastX = x
lastY = y
case tcell.ButtonSecondary:
mouseKey = MouseRight
case tcell.ButtonMiddle:
mouseKey = MouseMiddle
}
}
switch tev.Buttons() {
@ -179,11 +199,9 @@ func pollEvent() GocuiEvent {
if lastMouseKey != tcell.ButtonNone {
switch lastMouseKey {
case tcell.ButtonPrimary:
mouseKey = MouseLeft
dragState = NOT_DRAGGING
case tcell.ButtonSecondary:
mouseKey = MouseRight
case tcell.ButtonMiddle:
mouseKey = MouseMiddle
}
mouseMod = Modifier(lastMouseMod)
lastMouseMod = tcell.ModNone
@ -191,6 +209,17 @@ func pollEvent() GocuiEvent {
}
}
switch dragState {
// if we haven't released the left mouse button and we've moved the cursor then we're dragging
case MAYBE_DRAGGING:
if x != lastX || y != lastY {
dragState = DRAGGING
}
case DRAGGING:
mouseMod = ModMotion
mouseKey = MouseLeft
}
return GocuiEvent{
Type: eventMouse,
MouseX: x,