From 8e4da7f8279e331754dcac3aa332549c4c9842fe Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sun, 2 Jun 2024 14:06:49 +0100 Subject: [PATCH] fix: resolve index out of range bug in word wrap Resolved the index out of range [-1] bug from the word wrap function by checking the cursors' positions before evaluating the preceding character. --- internal/utilities/wrap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/utilities/wrap.go b/internal/utilities/wrap.go index d95173c..55a4c40 100644 --- a/internal/utilities/wrap.go +++ b/internal/utilities/wrap.go @@ -39,9 +39,9 @@ func wrapLine(line, separator string, charLimit int) string { var builder strings.Builder for rightcursor < (len(line) - charLimit) { - rightcursor += charLimit + rightcursor += (charLimit - 1) - for !unicode.IsSpace(rune(line[rightcursor-1])) && (rightcursor > leftcursor) { + for (rightcursor > leftcursor) && !unicode.IsSpace(rune(line[rightcursor-1])) { rightcursor-- }