From 5cf81f1cb1e5a1b54dc9421b763b683b6275fb57 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Sun, 31 Jul 2022 22:37:59 +0200 Subject: [PATCH] autocompletion: fix regression Commit 27425c15c4b9 ("autocompletion: fix slice out of bounds access") introduced a regression in the autocompletion that messes up the order of last entered chars when autocompletion runs. The ranges for a slice a[low:high] are 0 <= low <= high <= len(a) [0] To reproduce with the ":cf" command: 1) enter ":c" 2) wait for autocompleteion 3) enter "f" 4) the prompt will now be ":fc" [0]: https://go.dev/ref/spec#Slice_expressions Fixes: 27425c15c4b9 ("autocompletion: fix slice out of bounds access") Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/ui/textinput.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index f09ebb4..9d1de96 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -70,8 +70,8 @@ func (ti *TextInput) String() string { } func (ti *TextInput) StringLeft() string { - for ti.index >= len(ti.text) { - ti.index = len(ti.text) - 1 + for ti.index > len(ti.text) { + ti.index = len(ti.text) } return string(ti.text[:ti.index]) }