From e8713db1993430ff10270275fc7431c717018303 Mon Sep 17 00:00:00 2001 From: c-bata Date: Fri, 22 Jun 2018 16:41:45 +0900 Subject: [PATCH] Fix a truncate issue --- completion.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/completion.go b/completion.go index 6054437..283f0fb 100644 --- a/completion.go +++ b/completion.go @@ -139,7 +139,14 @@ func formatTexts(o []string, max int, prefix, suffix string) (new []string, widt spaces := strings.Repeat(" ", width-x) n[i] = prefix + o[i] + spaces + suffix } else if x > width { - n[i] = prefix + runewidth.Truncate(o[i], width, "...") + suffix + x := runewidth.Truncate(o[i], width, shortenSuffix) + // When calling runewidth.Truncate("您好xxx您好xxx", 11, "...") returns "您好xxx..." + // But the length of this result is 10. So we need to insert a space. + if l := runewidth.StringWidth(x); l < width { + spaces := strings.Repeat(" ", width - l) + x += spaces + } + n[i] = prefix + x + suffix } } return n, lenPrefix + width + lenSuffix