summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2016-02-15 23:51:51 +0000
committerAndy Williams <andy@andywilliams.me>2016-02-15 23:51:51 +0000
commitd985b3a9cd50b16097b5cefc9e6050b7aeba3e29 (patch)
tree93b137ebb8920e88bec29823f3af40a15e029712
parent1dbc1965ff6856820943c80649ecf8b15c4c1fb5 (diff)
downloadefl-d985b3a9cd50b16097b5cefc9e6050b7aeba3e29.tar.gz
[editor] stop auto selection on symbols too
-rw-r--r--legacy/elm_code/src/lib/widget/elm_code_widget_selection.c13
-rw-r--r--legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c78
2 files changed, 87 insertions, 4 deletions
diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c
index ae2d1226cf..6479123ff5 100644
--- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c
+++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c
@@ -6,6 +6,8 @@
#include "elm_code_widget_private.h"
+static char _breaking_chars[] = " \t,.?!;:()[]{}";
+
static Elm_Code_Widget_Selection_Data *
_elm_code_widget_selection_new()
{
@@ -245,12 +247,15 @@ elm_code_widget_selection_select_line(Evas_Object *widget, unsigned int line)
static Eina_Bool
_elm_code_widget_selection_char_breaks(char chr)
{
+ unsigned int i;
+
if (chr == 0)
return EINA_TRUE;
- else if (chr == ' ')
- return EINA_TRUE;
- else if (chr == '\t')
- return EINA_TRUE;
+
+ for (i = 0; i < sizeof(_breaking_chars); i++)
+ if (chr == _breaking_chars[i])
+ return EINA_TRUE;
+
return EINA_FALSE;
}
diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c
index 71e63bfe3e..9769f6bcd0 100644
--- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c
+++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c
@@ -539,6 +539,82 @@ START_TEST (elm_code_test_widget_selection_select_word)
}
END_TEST
+START_TEST (elm_code_test_widget_selection_select_word_punctuation)
+{
+ Elm_Code *code;
+ Elm_Code_File *file;
+ Elm_Code_Widget *widget;
+ Evas_Object *win;
+ char *selection;
+
+ elm_init(1, NULL);
+ code = elm_code_create();
+ file = elm_code_file_new(code);
+ elm_code_file_line_append(file, "comma, stop. question? mark!", 38, NULL);
+
+ win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
+ widget = elm_code_widget_add(win, code);
+
+ elm_code_widget_selection_select_word(widget, 1, 3);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("comma", selection);
+ free(selection);
+
+ elm_code_widget_selection_select_word(widget, 1, 10);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("stop", selection);
+ free(selection);
+
+ elm_code_widget_selection_select_word(widget, 1, 20);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("question", selection);
+ free(selection);
+
+ elm_code_widget_selection_select_word(widget, 1, 25);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("mark", selection);
+ free(selection);
+}
+END_TEST
+
+START_TEST (elm_code_test_widget_selection_select_word_symbols)
+{
+ Elm_Code *code;
+ Elm_Code_File *file;
+ Elm_Code_Widget *widget;
+ Evas_Object *win;
+ char *selection;
+
+ elm_init(1, NULL);
+ code = elm_code_create();
+ file = elm_code_file_new(code);
+ elm_code_file_line_append(file, "colon: [array] (brackets) {braces}", 38, NULL);
+
+ win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
+ widget = elm_code_widget_add(win, code);
+
+ elm_code_widget_selection_select_word(widget, 1, 3);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("colon", selection);
+ free(selection);
+
+ elm_code_widget_selection_select_word(widget, 1, 10);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("array", selection);
+ free(selection);
+
+ elm_code_widget_selection_select_word(widget, 1, 20);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("brackets", selection);
+ free(selection);
+
+ elm_code_widget_selection_select_word(widget, 1, 30);
+ selection = elm_code_widget_selection_text_get(widget);
+ ck_assert_str_eq("braces", selection);
+ free(selection);
+}
+END_TEST
+
void elm_code_test_widget_selection(TCase *tc)
{
tcase_add_test(tc, elm_code_test_widget_selection_set);
@@ -557,5 +633,7 @@ void elm_code_test_widget_selection(TCase *tc)
tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_multiline);
tcase_add_test(tc, elm_code_test_widget_selection_select_line);
tcase_add_test(tc, elm_code_test_widget_selection_select_word);
+ tcase_add_test(tc, elm_code_test_widget_selection_select_word_punctuation);
+ tcase_add_test(tc, elm_code_test_widget_selection_select_word_symbols);
}