From 4764c144c704ebb1c902cf53f704d6afd010ed62 Mon Sep 17 00:00:00 2001 From: Alexey Yerin Date: Mon, 17 May 2021 20:35:53 +0300 Subject: 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. --- ui/editor.go | 6 +++--- 1 file 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 { -- cgit v1.2.3