palm-client: wrapping doesn't split a @[Name] mention across lines (it stays one chip) unless the mention alone is longer than the line

This commit is contained in:
rich committed 2026-11-04 07:39:45 -05:00
1 parent aa3a5da9fe
commit 2643a2b40e
2 files changed
+25 -4

No files matched your search

+19 -4
View File
@@ -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;
+6
View File
@@ -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);