summaryrefslogtreecommitdiff
path: root/desktop/textarea.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-03-20 19:24:53 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-03-20 19:24:53 +0000
commitc568a9626b13405a53ea12c49766a4f2f67db506 (patch)
tree3bb9f061d1ad6dcd60ed5dde5c0fc0abd181878f /desktop/textarea.c
parent50efd110b8cbca87cc3c5c6065b2e498301c04c6 (diff)
downloadnetsurf-c568a9626b13405a53ea12c49766a4f2f67db506.tar.gz
netsurf-c568a9626b13405a53ea12c49766a4f2f67db506.tar.bz2
Avoid double redraw when edit causes scroll.
Diffstat (limited to 'desktop/textarea.c')
-rw-r--r--desktop/textarea.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/desktop/textarea.c b/desktop/textarea.c
index 03f8912ff..212cc5b03 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -300,7 +300,7 @@ static bool textarea_scroll_visible(struct textarea *ta)
*
* \param ta Text area
* \param caret_b Byte offset to caret
- * \return true iff caret placed
+ * \return true iff caret placement caused a scroll
*/
static bool textarea_set_caret_internal(struct textarea *ta, int caret_b)
{
@@ -311,7 +311,7 @@ static bool textarea_set_caret_internal(struct textarea *ta, int caret_b)
int x0, y0, x1, y1;
int width, height;
struct textarea_msg msg;
- bool scrolled;
+ bool scrolled = false;
if (caret_b != -1 && caret_b > (signed)(ta->show->len - 1))
caret_b = ta->show->len - 1;
@@ -353,8 +353,6 @@ static bool textarea_set_caret_internal(struct textarea *ta, int caret_b)
/* Finally, redraw the caret */
index = textarea_get_caret(ta);
- if (index == -1)
- return false;
/* find byte offset of caret position */
b_off = index;
@@ -442,7 +440,7 @@ static bool textarea_set_caret_internal(struct textarea *ta, int caret_b)
ta->callback(ta->data, &msg);
}
- return true;
+ return scrolled;
}
@@ -1109,7 +1107,7 @@ static size_t textarea_get_b_off_xy(struct textarea *ta, int x, int y,
* \param x X coordinate
* \param y Y coordinate
* \param visible true iff (x,y) is wrt visiable area, false for global
- * \return true on success false otherwise
+ * \return true iff caret placement caused a scroll
*/
static bool textarea_set_caret_xy(struct textarea *ta, int x, int y,
bool visible)
@@ -1640,15 +1638,17 @@ bool textarea_set_caret(struct textarea *ta, int caret)
{
int b_off;
- if (caret < 0)
- return textarea_set_caret_internal(ta, -1);
- else if (caret == 0)
- return textarea_set_caret_internal(ta, 0);
-
- b_off = utf8_bounded_byte_length(ta->show->data,
- ta->show->len - 1, caret);
+ if (caret < 0) {
+ textarea_set_caret_internal(ta, -1);
+ } else if (caret == 0) {
+ textarea_set_caret_internal(ta, 0);
+ } else {
+ b_off = utf8_bounded_byte_length(ta->show->data,
+ ta->show->len - 1, caret);
+ textarea_set_caret_internal(ta, b_off);
+ }
- return textarea_set_caret_internal(ta, b_off);
+ return true;
}
@@ -2161,7 +2161,6 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
x = ta->caret_x;
y = ta->text_y_offset_baseline + line * ta->line_height;
textarea_set_caret_xy(ta, x, y, false);
- caret = textarea_get_caret(ta);
return true;
case KEY_DOWN:
@@ -2359,7 +2358,7 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
return false;
}
- textarea_set_caret_internal(ta, caret);
+ redraw &= ~textarea_set_caret_internal(ta, caret);
/* TODO: redraw only the bit that changed */
if (redraw) {