diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-24 20:00:56 +1000 |
---|---|---|
committer | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2020-08-24 10:02:08 +0000 |
commit | 22c7110349109a0fb315873ea37f5d9cb6678990 (patch) | |
tree | b9bfeb9b9513f51e6cafce190772e855172a1fee /vendor | |
parent | 44ee28bb2ee69684cac7982626bea12074a8af31 (diff) |
prevent moving cursor past last character in prompt modal
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/gui.go | 14 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index 1426fc277..35efa49da 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -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 } diff --git a/vendor/modules.txt b/vendor/modules.txt index 863583aeb..3205beebf 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -99,7 +99,7 @@ github.com/hashicorp/hcl/json/token github.com/integrii/flaggy # github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 github.com/jbenet/go-context/io -# github.com/jesseduffield/gocui v0.3.1-0.20200823073938-1a970a28d894 +# github.com/jesseduffield/gocui v0.3.1-0.20200824095914-9ea1e384f70d ## explicit github.com/jesseduffield/gocui # github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe |