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:
parent
c6c711c29b
commit
8e4da7f827
1 changed files with 2 additions and 2 deletions
|
@ -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--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue