Skip to content

Commit 19a9e29

Browse files
authored
Merge pull request ActiveState#3366 from ActiveState/mitchell/dx-2909
Fixed wrapped length calculation.
2 parents 9e0c2c1 + ec5c793 commit 19a9e29

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

internal/colorize/cropped.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func GetCroppedText(text string, maxLen int, includeLineEnds bool) CroppedLines
3030
if len(text) > len(indent) && strings.HasPrefix(text[len(indent):], "• ") {
3131
indent += " "
3232
}
33-
maxLen -= len(indent)
3433
}
3534

3635
entries := make([]CroppedLine, 0)
@@ -53,7 +52,7 @@ func GetCroppedText(text string, maxLen int, includeLineEnds bool) CroppedLines
5352
// Ensure the next position is not within a color tag and check conditions that would end this entry
5453
if isLineEnd || (!inRange(pos+1, colorCodes) && (entry.Length == maxLen || pos == len(text)-1)) {
5554
wrapped := ""
56-
wrappedLength := 0
55+
wrappedLength := len(indent)
5756
nextCharIsSpace := pos+1 < len(text) && isSpace(text[pos+1])
5857
if !isLineEnd && entry.Length == maxLen && !nextCharIsSpace && pos < len(text)-1 {
5958
// Put the current word on the next line, if possible.
@@ -76,7 +75,7 @@ func GetCroppedText(text string, maxLen int, includeLineEnds bool) CroppedLines
7675
entry.Length -= wrappedLength
7776
isLineEnd = true // emulate for wrapping purposes
7877
} else {
79-
wrappedLength = 0 // reset
78+
wrappedLength = len(indent) // reset
8079
}
8180
}
8281
entries = append(entries, entry)

0 commit comments

Comments
 (0)