diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-02-16 21:31:10 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-02-18 10:19:34 +1100 |
commit | c517d1e0a2c02561afd4dabedafccd6ca11a82ee (patch) | |
tree | d0e7071da8d4827feeec99641cf10671c286e920 /vendor | |
parent | 8cad8cda8fa742c7c2a6cf52848104cef3b4d7d4 (diff) |
update view cursor when selecting new line in patch explorer view
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/gui.go | 19 | ||||
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/view.go | 33 |
2 files changed, 43 insertions, 9 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index b8b855f1d..8a47aa599 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -1226,8 +1226,10 @@ func (g *Gui) onKey(ev *GocuiEvent) error { newCx = lastCharForLine } } - if err := v.SetCursor(newCx, newCy); err != nil { - return err + if !IsMouseScrollKey(ev.Key) { + if err := v.SetCursor(newCx, newCy); err != nil { + return err + } } if IsMouseKey(ev.Key) { @@ -1289,6 +1291,19 @@ func IsMouseKey(key interface{}) bool { } } +func IsMouseScrollKey(key interface{}) bool { + switch key { + case + MouseWheelUp, + MouseWheelDown, + MouseWheelLeft, + MouseWheelRight: + return true + default: + return false + } +} + // execKeybindings executes the keybinding handlers that match the passed view // and event. The value of matched is true if there is a match and no errors. func (g *Gui) execKeybindings(v *View, ev *GocuiEvent) (matched bool, err error) { diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go index aa9dbd214..d8984253d 100644 --- a/vendor/github.com/jesseduffield/gocui/view.go +++ b/vendor/github.com/jesseduffield/gocui/view.go @@ -418,9 +418,10 @@ func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error { if err != nil { return err } - _, rcy, err = v.realPosition(v.cx, v.cy) - if err != nil { - return err + _, rrcy, err := v.realPosition(v.cx, v.cy) + // if error is not nil, then the cursor is out of bounds, which is fine + if err == nil { + rcy = rrcy } } @@ -460,6 +461,22 @@ func (v *View) SetCursor(x, y int) error { return nil } +func (v *View) SetCursorX(x int) { + maxX, _ := v.Size() + if x < 0 || x >= maxX { + return + } + v.cx = x +} + +func (v *View) SetCursorY(y int) { + _, maxY := v.Size() + if y < 0 || y >= maxY { + return + } + v.cy = y +} + // Cursor returns the cursor position of the view. func (v *View) Cursor() (x, y int) { return v.cx, v.cy @@ -1349,11 +1366,12 @@ func (v *View) OverwriteLines(y int, content string) { } func (v *View) ScrollUp(amount int) { - newOy := v.oy - amount - if newOy < 0 { - newOy = 0 + if amount > v.oy { + amount = v.oy } - v.oy = newOy + + v.oy -= amount + v.cy += amount } // ensures we don't scroll past the end of the view's content @@ -1361,6 +1379,7 @@ func (v *View) ScrollDown(amount int) { adjustedAmount := v.adjustDownwardScrollAmount(amount) if adjustedAmount > 0 { v.oy += adjustedAmount + v.cy -= adjustedAmount } } |