From 2643a2b40ed99cd1c1c61163f83a5ee04de3b6c6 Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Wed, 4 Nov 2026 07:39:45 -0500 Subject: [PATCH] palm-client: wrapping doesn't split a @[Name] mention across lines (it stays one chip) unless the mention alone is longer than the line --- palm-client/src/ui/text.c | 23 +++++++++++++++++++---- palm-client/tests/test_text.c | 6 ++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/palm-client/src/ui/text.c b/palm-client/src/ui/text.c index 3debe4f..2e79f5c 100644 --- a/palm-client/src/ui/text.c +++ b/palm-client/src/ui/text.c @@ -37,7 +37,8 @@ UInt16 TxtFit(const Char *s, UInt16 len, Int16 maxW, TxtWidthFn w) UInt16 TxtWrap(const Char *s, UInt16 len, Int16 maxW, TxtWidthFn w, UInt16 *consumed) { - UInt16 fit, brk, end, nl; + UInt16 fit, brk, end, nl, i, any; + Boolean inMention; /* a line break in the text ends the line there, if it comes before the wrap point */ for (nl = 0; nl < len && s[nl] != '\n' && s[nl] != '\r'; nl++) @@ -56,9 +57,23 @@ UInt16 TxtWrap(const Char *s, UInt16 len, Int16 maxW, TxtWidthFn w, UInt16 *cons } if (fit == 0) fit = 1; /* always make progress, even if one character is too wide */ - /* break after the last space in the part that fits */ - for (brk = fit; brk > 0 && s[brk] != ' '; brk--) - ; + /* + * Break at the last space in the part that fits, but not inside a + * @[Name] mention (drawn as one chip) unless it's longer than the line. + */ + for (i = 0, any = 0, brk = 0, inMention = 0; i <= fit; i++) { + if (s[i] == ' ' && i > 0) { + any = i; + if (!inMention) + brk = i; + } else if (s[i] == '@' && i + 1 < len && s[i + 1] == '[') { + inMention = 1; + } else if (s[i] == ']') { + inMention = 0; + } + } + if (brk == 0) + brk = any; if (brk == 0) brk = fit; /* one word longer than the line: break it */ end = brk; diff --git a/palm-client/tests/test_text.c b/palm-client/tests/test_text.c index 5053d2b..fa45152 100644 --- a/palm-client/tests/test_text.c +++ b/palm-client/tests/test_text.c @@ -55,6 +55,12 @@ static void test_fit_and_wrap(void) n = TxtWrap("abcdef ghij\nk", 13, 5 * 4, Four, &used); /* the width wraps before the break */ CHECK(n == 5 && used == 5); + /* a mention isn't split, unless it alone is longer than the line */ + n = TxtWrap("hi @[Ann Lee] ok", 16, 12 * 4, Four, &used); + CHECK(n == 2 && used == 3); + n = TxtWrap("@[A very long name] x", 21, 10 * 4, Four, &used); + CHECK(n == 8 && used == 9); /* at its last space, as before */ + /* the rest fits */ n = TxtWrap("short", 5, 100, Four, &used); CHECK(n == 5 && used == 5);