aboutsummaryrefslogtreecommitdiffstats
path: root/util/text/text.go
diff options
context:
space:
mode:
authorYang Zhang <yang_zhang@iapcm.ac.cn>2019-01-08 09:55:32 +0800
committerYang Zhang <yang_zhang@iapcm.ac.cn>2019-01-08 09:55:32 +0800
commit8ea5c6b41de8a0ccdff245456c317a2ad98cd630 (patch)
tree9509b9bd382f800ce49e923aea4960b54db2b44d /util/text/text.go
parent2feb4ec21b875a9f444033fd81ee9af63e46819b (diff)
downloadgit-bug-8ea5c6b41de8a0ccdff245456c317a2ad98cd630.tar.gz
Fix handling of long words
Diffstat (limited to 'util/text/text.go')
-rw-r--r--util/text/text.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/util/text/text.go b/util/text/text.go
index f59bdbfb..81cc870b 100644
--- a/util/text/text.go
+++ b/util/text/text.go
@@ -89,9 +89,16 @@ func softwrapLine(line string, textWidth int) string {
width = 0
}
} else if wl > textWidth {
- left, right := splitWord(chunks[len(chunks)-1], textWidth)
- line2 += left + "\n"
+ // NOTE: By default, long words are splited to fill the remaining space.
+ // But if the long words is the first non-space word in the middle of the
+ // line, preceeding spaces shall not be counted in word spliting.
+ splitWidth := textWidth - width
+ if strings.HasSuffix(line2, "\n"+strings.Repeat(" ", width)) {
+ splitWidth += width
+ }
+ left, right := splitWord(chunks[len(chunks)-1], splitWidth)
chunks[len(chunks)-1] = right
+ line2 += left + "\n"
width = 0
} else {
line2 += "\n"