summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-03-20 12:41:06 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-03-20 12:41:06 +0000
commit8cfa964cdf889ce80517ecf0e1fac708baea7837 (patch)
treec59a2729c639c232c712a1546c5198272aec4766
parent5f7ed448d42fca3486f227e11f981c46c93ed2b8 (diff)
downloadnetsurf-8cfa964cdf889ce80517ecf0e1fac708baea7837.tar.gz
netsurf-8cfa964cdf889ce80517ecf0e1fac708baea7837.tar.bz2
Start reflow on line before change in text, rather than always reflowing the entire textarea.
-rw-r--r--desktop/textarea.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/desktop/textarea.c b/desktop/textarea.c
index 61ac0bbc4..db5cc362d 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -835,8 +835,12 @@ static bool textarea_reflow(struct textarea *ta, unsigned int start)
if ((signed)start > ta->line_count)
start = 0;
- /** \todo pay attention to start param, for now force start at zero */
- start = 0;
+
+ /* Have to start on line before where the changes are in case an
+ * added space makes the text before the space on a soft-wrapped line
+ * fit on the line above */
+ if (start != 0)
+ start--;
do {
/* Set line count to start point */
@@ -852,6 +856,15 @@ static bool textarea_reflow(struct textarea *ta, unsigned int start)
avail_width = 0;
h_extent = avail_width;
+ /* Set up initial length and text offset */
+ if (line == 0) {
+ len = ta->text.len - 1;
+ text = ta->text.data;
+ } else {
+ len = ta->text.len - 1 - ta->lines[line].b_start;
+ text = ta->text.data + ta->lines[line].b_start;
+ }
+
if (ta->text.len == 1) {
/* Handle empty textarea */
assert(ta->text.data[0] == '\0');
@@ -861,9 +874,7 @@ static bool textarea_reflow(struct textarea *ta, unsigned int start)
}
restart = false;
- for (len = ta->text.len - 1, text = ta->text.data; len > 0;
- len -= b_off, text += b_off) {
-
+ for (; len > 0; len -= b_off, text += b_off) {
/* Find end of paragraph */
for (para_end = text; para_end < text + len;
para_end++) {
@@ -1108,7 +1119,7 @@ static bool textarea_set_caret_xy(struct textarea *ta, int x, int y,
static bool textarea_insert_text(struct textarea *ta, const char *text,
size_t b_off, size_t b_len, int *byte_delta)
{
- int char_delta;
+ int char_delta, line;
if (ta->flags & TEXTAREA_READONLY)
return true;
@@ -1159,8 +1170,11 @@ static bool textarea_insert_text(struct textarea *ta, const char *text,
*byte_delta = ta->text.len - *byte_delta;
}
- /** \todo calculate line to reflow from */
- return textarea_reflow(ta, 0);
+ for (line = 0; line < ta->line_count - 1; line++)
+ if (ta->lines[line + 1].b_start > b_off)
+ break;
+
+ return textarea_reflow(ta, line);
}
@@ -1210,7 +1224,7 @@ static bool textarea_replace_text(struct textarea *ta, size_t b_start,
size_t b_end, const char *rep, size_t rep_len,
bool add_to_clipboard, int *byte_delta)
{
- int char_delta;
+ int char_delta, line;
*byte_delta = 0;
if ((ta->flags & TEXTAREA_READONLY) &&
@@ -1290,8 +1304,11 @@ static bool textarea_replace_text(struct textarea *ta, size_t b_start,
*byte_delta = ta->text.len - *byte_delta;
}
- /** \todo calculate line to reflow from */
- return textarea_reflow(ta, 0);
+ for (line = 0; line < ta->line_count - 1; line++)
+ if (ta->lines[line + 1].b_start > b_start)
+ break;
+
+ return textarea_reflow(ta, line);
}