diff options
author | Alexey Yerin <yyp@disroot.org> | 2021-05-17 20:35:53 +0300 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-17 21:22:08 +0200 |
commit | 4764c144c704ebb1c902cf53f704d6afd010ed62 (patch) | |
tree | 9a1eab381730ceb513b24e7b4d574e73939f822e | |
parent | Update tcell to 2.3.1 (diff) |
ui/editor: add boundary checks for word actions
Prior to this, if the input is spaced out (whitespace skip), word
movements caused senpai to crash because there were no boundary checks.
Diffstat (limited to '')
-rw-r--r-- | ui/editor.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/ui/editor.go b/ui/editor.go index 12b0f24..444768c 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -128,7 +128,7 @@ func (e *Editor) RemWord() (ok bool) { // Hello world| // Hello | // | - for line[e.cursorIdx-1] == ' ' { + for e.cursorIdx > 0 && line[e.cursorIdx-1] == ' ' { e.remRuneAt(e.cursorIdx - 1) e.Left() } @@ -186,7 +186,7 @@ func (e *Editor) RightWord() { return } - for line[e.cursorIdx] == ' ' { + for e.cursorIdx < len(line) && line[e.cursorIdx] == ' ' { e.Right() } for i := e.cursorIdx; i < len(line) && line[i] != ' '; i += 1 { @@ -214,7 +214,7 @@ func (e *Editor) LeftWord() { line := e.text[e.lineIdx] - for line[e.cursorIdx-1] == ' ' { + for e.cursorIdx > 0 && line[e.cursorIdx-1] == ' ' { e.Left() } for i := e.cursorIdx - 1; i >= 0 && line[i] != ' '; i -= 1 { |