summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/textarea.c40
-rw-r--r--desktop/textarea.h8
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) {
@@ -2350,6 +2338,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)
{
if (width != NULL)
diff --git a/desktop/textarea.h b/desktop/textarea.h
index d01cd12c6..3fedeee35 100644
--- a/desktop/textarea.h
+++ b/desktop/textarea.h
@@ -198,6 +198,14 @@ 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
*
* \param ta textarea widget