hints kitten: Preserve line breaks when the hint is over a line break

Fixes #8674
This commit is contained in:
Kovid Goyal
2025-05-24 14:09:27 +05:30
parent 8e720cc1da
commit 5faa7bda5d
2 changed files with 23 additions and 0 deletions

View File

@@ -203,6 +203,27 @@ func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
if len(mark_text) <= len(hint) {
mark_text = ""
} else {
replaced_text := mark_text[:len(hint)]
replaced_text = strings.ReplaceAll(replaced_text, "\r", "\n")
if strings.Contains(replaced_text, "\n") {
buf := strings.Builder{}
buf.Grow(2 * len(hint))
h := hint
parts := strings.Split(replaced_text, "\n")
for i, x := range parts {
if x != "" {
buf.WriteString(h[:len(x)])
h = h[len(x):]
}
if i != len(parts)-1 {
buf.WriteString("\n")
}
}
if h != "" {
buf.WriteString(h)
}
hint = buf.String()
}
mark_text = mark_text[len(hint):]
}
ans := hint_style(hint) + text_style(mark_text)