From 2158ef60a871a434450021fd5588820ff93fbefa Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 10 Jan 2013 17:42:43 +0000 Subject: Improve reflow in multiline textareas. --- desktop/textarea.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'desktop') diff --git a/desktop/textarea.c b/desktop/textarea.c index 79b1ed436..e5f140dfa 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -335,6 +335,12 @@ static bool textarea_reflow(struct textarea *ta, unsigned int line) ta->vis_width - MARGIN_LEFT - MARGIN_RIGHT, &b_off, &x); + if (b_off == 0) { + /* Text wasn't split */ + b_off = len; + } + /* b_off now marks space, or end of text */ + if (line_count > 0 && line_count % LINE_CHUNK_SIZE == 0) { struct line_info *temp = realloc(ta->lines, (line_count + LINE_CHUNK_SIZE) * @@ -352,8 +358,9 @@ static bool textarea_reflow(struct textarea *ta, unsigned int line) if (*space == '\n') break; } + /* space now marks newline, or b_off -- whichever's first */ - if (space <= text + b_off) { + if (space < text + b_off) { /* Found newline; use it */ ta->lines[line_count].b_start = text - ta->text; ta->lines[line_count++].b_length = space - text; @@ -368,10 +375,9 @@ static bool textarea_reflow(struct textarea *ta, unsigned int line) } continue; - } - if (len - b_off > 0) { - /* find last space (if any) */ + } else if (len - b_off > 0) { + /* soft wraped, find last space (if any) */ for (space = text + b_off; space > text; space--) if (*space == ' ') break; -- cgit v1.2.3