summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranjal Kole <pranjal.kole7@gmail.com>2022-01-23 10:04:50 +0530
committerMichael Drake <tlsa@netsurf-browser.org>2022-01-23 14:22:40 +0000
commit4fc78449ff6fe7042aadf0f9e3706adbb21066d3 (patch)
tree25d220050011345104a21cf22569e31bdc54d1e1
parent88d5ea866858506aae2ff2ecbdee2b4f960ab89f (diff)
downloadnetsurf-4fc78449ff6fe7042aadf0f9e3706adbb21066d3.tar.gz
netsurf-4fc78449ff6fe7042aadf0f9e3706adbb21066d3.tar.bz2
textarea: always clear selection on NS_KEY_WORD_{LEFT,RIGHT}
This bug can be seen by selecting some text starting from the beginning of a textarea (so that caret is 0) and then pressing the NS_KEY_WORD_LEFT binding. NS_KEY_WORD_LEFT was breaking early when caret was 0. So, to always clear the selection, the clear selection code has been brought above the break statement. NS_KEY_WORD_RIGHT did not have such a break statement, so one has been added for consistency, and because string operations are expensive.
-rw-r--r--desktop/textarea.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/desktop/textarea.c b/desktop/textarea.c
index e25c6335f..e0e87444c 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -2743,6 +2743,9 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
case NS_KEY_WORD_LEFT:
if (readonly)
break;
+ if (ta->sel_start != -1) {
+ textarea_clear_selection(ta);
+ }
if (caret == 0)
break;
caret--;
@@ -2756,9 +2759,6 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
break;
}
}
- if (ta->sel_start != -1) {
- textarea_clear_selection(ta);
- }
break;
case NS_KEY_DELETE_WORD_LEFT:
if (readonly)
@@ -2807,6 +2807,11 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
case NS_KEY_WORD_RIGHT:
if (readonly)
break;
+ if (ta->sel_start != -1) {
+ textarea_clear_selection(ta);
+ }
+ if (caret == ta->show->len - 1)
+ break;
if (strchr(sep, ta->show->data[caret]) != NULL &&
caret < ta->show->len - 1) {
while (strchr(sep, ta->show->data[caret]) !=
@@ -2823,9 +2828,6 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
while (strchr(sep, ta->show->data[caret]) != NULL &&
caret < ta->show->len - 1)
caret++;
- if (ta->sel_start != -1) {
- textarea_clear_selection(ta);
- }
break;
case NS_KEY_DELETE_WORD_RIGHT:
if (readonly)