From 553c55b07a4aeb190f18806058f51ce2a10d9dd6 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 13 Feb 2013 13:37:46 +0000 Subject: Move selection clearing into a function, and expose it in the header file. --- desktop/textarea.c | 40 ++++++++++++++++++++++++++-------------- desktop/textarea.h | 8 ++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/desktop/textarea.c b/desktop/textarea.c index 0426b007a..455e9a4ca 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -1934,10 +1934,7 @@ bool textarea_keypress(struct textarea *ta, uint32_t key) case KEY_ESCAPE: /* Fall through to KEY_CLEAR_SELECTION */ case KEY_CLEAR_SELECTION: - ta->sel_start = -1; - ta->sel_end = -1; - redraw = true; - break; + return textarea_clear_selection(ta); case KEY_LEFT: if (readonly) break; @@ -2272,16 +2269,7 @@ bool textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, } if (ta->sel_start != -1) { /* Clear selection */ - ta->sel_start = ta->sel_end = -1; - - msg.ta = ta; - msg.type = TEXTAREA_MSG_REDRAW_REQUEST; - msg.data.redraw.x0 = 0; - msg.data.redraw.y0 = 0; - msg.data.redraw.x1 = ta->vis_width; - msg.data.redraw.y1 = ta->vis_height; - - ta->callback(ta->data, &msg); + textarea_clear_selection(ta); } } else if (mouse & BROWSER_MOUSE_PRESS_2) { @@ -2349,6 +2337,30 @@ bool textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, } +/* exported interface, documented in textarea.h */ +bool textarea_clear_selection(struct textarea *ta) +{ + struct textarea_msg msg; + + if (ta->sel_start == -1) + /* No selection to clear */ + return false; + + ta->sel_start = ta->sel_end = -1; + + msg.ta = ta; + msg.type = TEXTAREA_MSG_REDRAW_REQUEST; + msg.data.redraw.x0 = 0; + msg.data.redraw.y0 = 0; + msg.data.redraw.x1 = ta->vis_width; + msg.data.redraw.y1 = ta->vis_height; + + ta->callback(ta->data, &msg); + + return true; +} + + /* exported interface, documented in textarea.h */ void textarea_get_dimensions(struct textarea *ta, int *width, int *height) { diff --git a/desktop/textarea.h b/desktop/textarea.h index d01cd12c6..3fedeee35 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -197,6 +197,14 @@ bool textarea_keypress(struct textarea *ta, uint32_t key); bool textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, int x, int y); +/** + * Clear any selection in the textarea. + * + * \param ta textarea widget + * \return true if there was a selection to clear, false otherwise + */ +bool textarea_clear_selection(struct textarea *ta); + /** * Gets the dimensions of a textarea * -- cgit v1.2.3