From aa5d501a0db4cbddb1072dc8030813f91a1bd2eb Mon Sep 17 00:00:00 2001 From: erroneousboat Date: Sat, 12 Oct 2019 13:42:35 +0200 Subject: [PATCH] Scroll back text when using backspace Fixes #213 --- components/input.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/components/input.go b/components/input.go index 1a9a493..a71d98f 100644 --- a/components/input.go +++ b/components/input.go @@ -85,7 +85,18 @@ func (i *Input) Insert(key rune) { // Backspace will remove a character in front of the CursorPositionText func (i *Input) Backspace() { if i.CursorPositionText > 0 { - i.MoveCursorLeft() + + // We want the cursor to stay in the same spot when the text + // overflow, revealing the test on the left side when using + // backspace. When all the text has been revealed will move + // the cursor to the left. + if i.Offset > 0 { + i.Offset-- + i.CursorPositionText-- + } else { + i.MoveCursorLeft() + } + i.Text = append(i.Text[0:i.CursorPositionText], i.Text[i.CursorPositionText+1:]...) i.Par.Text = string(i.Text[i.Offset:]) }