From 5faa7bda5d7b45e7ae68ba07b9e150c32a2a7d4f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 24 May 2025 14:09:27 +0530 Subject: [PATCH] hints kitten: Preserve line breaks when the hint is over a line break Fixes #8674 --- docs/changelog.rst | 2 ++ kittens/hints/main.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 762349228..a299a3147 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -115,6 +115,8 @@ Detailed list of changes - Remote control: Fix holding a remote control socket open causing the kitty I/O thread to go into a loop and not respond on other remote control sockets (:disc:`8670`) +- hints kitten: Preserve line breaks when the hint is over a line break (:iss:`8674`) + 0.42.1 [2025-05-17] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/hints/main.go b/kittens/hints/main.go index 758c063b3..01fe864b3 100644 --- a/kittens/hints/main.go +++ b/kittens/hints/main.go @@ -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)