When truncating descriptions for completion truncate at word boundaries
This commit is contained in:
parent
a2f022d166
commit
5ad2ac259b
@ -8,6 +8,7 @@ import (
|
||||
"kitty/tools/cli/markup"
|
||||
"kitty/tools/tty"
|
||||
"kitty/tools/utils"
|
||||
"kitty/tools/utils/style"
|
||||
"kitty/tools/wcswidth"
|
||||
"strings"
|
||||
)
|
||||
@ -67,7 +68,7 @@ func (self *Match) FormatForCompletionList(max_word_len int, f *markup.Context,
|
||||
word += strings.Repeat(" ", max_word_len-word_len)
|
||||
}
|
||||
if wcswidth.Stringwidth(desc) > max_desc_len {
|
||||
desc = wcswidth.TruncateToVisualLength(desc, max_desc_len-2) + "\x1b[m\x1b]8;;\x1b\\…"
|
||||
desc = style.WrapTextAsLines(desc, "", max_desc_len-2)[0] + "…"
|
||||
}
|
||||
if multiline {
|
||||
return word + "\n" + strings.Repeat(" ", max_word_len+2) + desc
|
||||
|
||||
@ -448,9 +448,9 @@ func (self *wrapper) handle_osc(raw []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *wrapper) wrap_text(text string) string {
|
||||
func (self *wrapper) wrap_text(text string) []string {
|
||||
if text == "" {
|
||||
return text
|
||||
return []string{""}
|
||||
}
|
||||
self.current_line.reset()
|
||||
self.current_word.reset()
|
||||
@ -467,7 +467,7 @@ func (self *wrapper) wrap_text(text string) string {
|
||||
last_line = ""
|
||||
}
|
||||
self.append_line(last_line)
|
||||
return strings.Join(self.lines, "\n")
|
||||
return self.lines
|
||||
}
|
||||
|
||||
func new_wrapper(indent string, width int) *wrapper {
|
||||
@ -480,8 +480,12 @@ func new_wrapper(indent string, width int) *wrapper {
|
||||
return &ans
|
||||
}
|
||||
|
||||
func WrapText(text string, indent string, width int, ignore_lines_containing ...string) string {
|
||||
func WrapTextAsLines(text string, indent string, width int, ignore_lines_containing ...string) []string {
|
||||
w := new_wrapper(indent, width)
|
||||
w.ignore_lines_containing = ignore_lines_containing
|
||||
return w.wrap_text(text)
|
||||
}
|
||||
|
||||
func WrapText(text string, indent string, width int, ignore_lines_containing ...string) string {
|
||||
return strings.Join(WrapTextAsLines(text, indent, width, ignore_lines_containing...), "\n")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user