mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-19 00:28:03 +02:00
update view cursor when selecting new line in patch explorer view
This commit is contained in:
19
vendor/github.com/jesseduffield/gocui/gui.go
generated
vendored
19
vendor/github.com/jesseduffield/gocui/gui.go
generated
vendored
@ -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) {
|
||||
|
33
vendor/github.com/jesseduffield/gocui/view.go
generated
vendored
33
vendor/github.com/jesseduffield/gocui/view.go
generated
vendored
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user