1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-23 00:39:13 +02:00

prevent moving cursor past last character in prompt modal

This commit is contained in:
Jesse Duffield
2020-08-24 20:00:56 +10:00
committed by github-actions[bot]
parent 44ee28bb2e
commit 22c7110349
4 changed files with 18 additions and 2 deletions

View File

@ -833,6 +833,20 @@ func (g *Gui) onKey(ev *termbox.Event) error {
}
}
}
newCx := mx - v.x0 - 1
newCy := my - v.y0 - 1
// if view is editable don't go further than the furthest character for that line
if v.Editable && newCy >= 0 && newCy <= len(v.lines)-1 {
lastCharForLine := len(v.lines[newCy])
if lastCharForLine < newCx {
newCx = lastCharForLine
}
}
if err := v.SetCursor(newCx, newCy); err != nil {
return err
}
if err := v.SetCursor(mx-v.x0-1, my-v.y0-1); err != nil {
return err
}