diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 04ea8e5e6..a2c2cd9b5 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -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}, diff --git a/vendor/github.com/jesseduffield/gocui/edit.go b/vendor/github.com/jesseduffield/gocui/edit.go index f548ebd76..a47f45c9d 100644 --- a/vendor/github.com/jesseduffield/gocui/edit.go +++ b/vendor/github.com/jesseduffield/gocui/edit.go @@ -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 } diff --git a/vendor/github.com/jesseduffield/gocui/keybinding.go b/vendor/github.com/jesseduffield/gocui/keybinding.go index 00bdcd0bf..f9df6993b 100644 --- a/vendor/github.com/jesseduffield/gocui/keybinding.go +++ b/vendor/github.com/jesseduffield/gocui/keybinding.go @@ -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) ) diff --git a/vendor/github.com/jesseduffield/gocui/tcell_driver.go b/vendor/github.com/jesseduffield/gocui/tcell_driver.go index 2ede319a3..c7e313716 100644 --- a/vendor/github.com/jesseduffield/gocui/tcell_driver.go +++ b/vendor/github.com/jesseduffield/gocui/tcell_driver.go @@ -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,