1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-19 21:28:28 +02:00

bump gocui

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

View File

@ -1357,14 +1357,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleLBLMouseDown, Handler: gui.handleLBLMouseDown,
}, },
// TODO: see how to get mouse dragging in tcell {
// { ViewName: "main",
// ViewName: "main", Contexts: []string{MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY},
// Contexts: []string{MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY}, Key: gocui.MouseLeft,
// Key: gocui.MouseLeft, Modifier: gocui.ModMotion,
// Modifier: gocui.ModMotion, Handler: gui.handleMouseDrag,
// Handler: gui.handleMouseDrag, },
// },
{ {
ViewName: "main", ViewName: "main",
Contexts: []string{MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY}, 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]) olen := len(v.lines[y])
w := runewidth.RuneWidth(ch)
var s []cell var s []cell
if x >= len(v.lines[y]) { 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 { } else if !v.Overwrite {
s = make([]cell, 1) s = make([]cell, w)
} }
v.lines[y] = append(v.lines[y], s...) v.lines[y] = append(v.lines[y], s...)
if !v.Overwrite || (v.Overwrite && x >= olen-1) { if !v.Overwrite || (v.Overwrite && x >= olen-w) {
copy(v.lines[y][x+1:], v.lines[y][x:]) copy(v.lines[y][x+w:], v.lines[y][x:])
} }
v.lines[y][x] = cell{ v.lines[y][x] = cell{
fgColor: v.FgColor, fgColor: v.FgColor,
@ -374,6 +375,14 @@ func (v *View) writeRune(x, y int, ch rune) error {
chr: ch, chr: ch,
} }
for i := 1; i < w; i++ {
v.lines[y][x+i] = cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: '\x00',
}
}
return nil return nil
} }
@ -400,7 +409,7 @@ func (v *View) deleteRune(x, y int) (int, error) {
w := runewidth.RuneWidth(v.lines[y][i].chr) w := runewidth.RuneWidth(v.lines[y][i].chr)
tw += w tw += w
if tw > x { 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 return w, nil
} }

View File

@ -317,8 +317,9 @@ const (
// Modifiers. // Modifiers.
const ( const (
ModNone Modifier = Modifier(0) ModNone Modifier = Modifier(0)
ModAlt = Modifier(tcell.ModAlt) 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 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) // ModCtrl = Modifier(tcell.ModCtrl)
) )

View File

@ -104,9 +104,18 @@ const (
eventRaw eventRaw
) )
const (
NOT_DRAGGING int = iota
MAYBE_DRAGGING
DRAGGING
)
var ( var (
lastMouseKey tcell.ButtonMask = tcell.ButtonNone lastMouseKey tcell.ButtonMask = tcell.ButtonNone
lastMouseMod tcell.ModMask = tcell.ModNone lastMouseMod tcell.ModMask = tcell.ModNone
dragState int = NOT_DRAGGING
lastX int = 0
lastY int = 0
) )
// pollEvent get tcell.Event and transform it into gocuiEvent // pollEvent get tcell.Event and transform it into gocuiEvent
@ -172,6 +181,17 @@ func pollEvent() GocuiEvent {
if button != tcell.ButtonNone && lastMouseKey == tcell.ButtonNone { if button != tcell.ButtonNone && lastMouseKey == tcell.ButtonNone {
lastMouseKey = button lastMouseKey = button
lastMouseMod = tev.Modifiers() 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() { switch tev.Buttons() {
@ -179,11 +199,9 @@ func pollEvent() GocuiEvent {
if lastMouseKey != tcell.ButtonNone { if lastMouseKey != tcell.ButtonNone {
switch lastMouseKey { switch lastMouseKey {
case tcell.ButtonPrimary: case tcell.ButtonPrimary:
mouseKey = MouseLeft dragState = NOT_DRAGGING
case tcell.ButtonSecondary: case tcell.ButtonSecondary:
mouseKey = MouseRight
case tcell.ButtonMiddle: case tcell.ButtonMiddle:
mouseKey = MouseMiddle
} }
mouseMod = Modifier(lastMouseMod) mouseMod = Modifier(lastMouseMod)
lastMouseMod = tcell.ModNone 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{ return GocuiEvent{
Type: eventMouse, Type: eventMouse,
MouseX: x, MouseX: x,