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.
This commit is contained in:
Dan Anglin 2024-06-02 14:06:49 +01:00
parent c6c711c29b
commit 8e4da7f827
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638

View file

@ -39,9 +39,9 @@ func wrapLine(line, separator string, charLimit int) string {
var builder strings.Builder var builder strings.Builder
for rightcursor < (len(line) - charLimit) { 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-- rightcursor--
} }