From 978421e3b55833439b0701bf78a18974a17bb79e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 25 Mar 2021 15:08:57 +0200 Subject: Text: Trying more conservative word wrapping rules IssueID #201 --- src/ui/text.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/text.c b/src/ui/text.c index 8107b886..c4ad8172 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -836,6 +836,19 @@ static enum iFontId fontId_Text_(const iFont *font) { return (enum iFontId) (font - text_.fonts); } +iLocalDef iBool isWrapPunct_(iChar c) { + /* Punctuation that participates in word-wrapping. */ + return (c == '/' || c == '=' || c == '-' || c == ',' || c == ';' || c == '.' || c == ':' || c == 0xad); +} + +iLocalDef iBool isClosingBracket_(iChar c) { + return (c == ')' || c == ']' || c == '}' || c == '>'); +} + +iLocalDef iBool isBracket_(iChar c) { + return (c == '(' || c == '[' || c == '{' || c == '<' || isClosingBracket_(c)); +} + iLocalDef iBool isWrapBoundary_(iChar prevC, iChar c) { /* Line wrapping boundaries are determined by looking at a character and the last character processed. We want to wrap at natural word boundaries where @@ -844,14 +857,13 @@ iLocalDef iBool isWrapBoundary_(iChar prevC, iChar c) { can wrap text like foo/bar/baz-abc-def.xyz at any puncation boundaries, without wrapping on other punctuation used for expressive purposes like emoticons :-) */ - if (c == '.' && (prevC == '(' || prevC == '[' || prevC == '.')) { - /* Start of a [...], perhaps? */ - return iFalse; + if (isClosingBracket_(c)) { + return iTrue; } if (isSpace_Char(prevC)) { return iFalse; } - if (c == '/' || c == '-' || c == ',' || c == ';' || c == ':' || c == '.' || c == 0xad) { + if ((c == '/' || c == '-' || c == '_' || c == '+') && !isWrapPunct_(prevC)) { return iTrue; } return isSpace_Char(c); -- cgit v1.2.3