elm_code selection: test and implement single line

Multi line selection still to come
This commit is contained in:
Andy Williams 2015-03-25 21:55:00 +00:00
parent 7ffa533392
commit 35866daf6a
8 changed files with 106 additions and 4 deletions

View File

@ -74,6 +74,21 @@ elm_code_line_text_contains(Elm_Code_Line *line, const char *search)
return elm_code_line_text_strpos(line, search, 0) != ELM_CODE_TEXT_NOT_FOUND;
}
EAPI char *
elm_code_line_text_substr(Elm_Code_Line *line, unsigned int position, int length)
{
const char *content;
if (!line || length < 1)
return strdup("");
if (position + length > line->length)
length = line->length - position;
content = elm_code_line_text_get(line, NULL);
return strndup(content + position, length);
}
static void
_elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move)
{

View File

@ -30,6 +30,8 @@ EAPI int elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int
EAPI Eina_Bool elm_code_line_text_contains(Elm_Code_Line *line, const char *search);
EAPI char *elm_code_line_text_substr(Elm_Code_Line *line, unsigned int position, int length);
EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length);
EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length);

View File

@ -102,15 +102,24 @@ elm_code_widget_selection_clear(Evas_Object *widget)
eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget));
}
EAPI const char *
EAPI char *
elm_code_widget_selection_text_get(Evas_Object *widget)
{
Elm_Code_Widget_Data *pd;
Elm_Code_Line *line;
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
if (!pd->selection)
return "";
return strdup("");
return "TODO";
if (pd->selection->start_line == pd->selection->end_line)
{
line = elm_code_file_line_get(pd->code->file, pd->selection->start_line);
return elm_code_line_text_substr(line, pd->selection->start_col - 1,
pd->selection->end_col - pd->selection->start_col + 1);
}
return strdup("TODO");
}

View File

@ -21,7 +21,7 @@ EAPI void elm_code_widget_selection_end(Evas_Object *widget, unsigned int line,
EAPI void elm_code_widget_selection_clear(Evas_Object *widget);
EAPI const char *elm_code_widget_selection_text_get(Evas_Object *widget);
EAPI char *elm_code_widget_selection_text_get(Evas_Object *widget);
/**
* @}

View File

@ -12,6 +12,7 @@ elm_code_test_basic.c \
elm_code_test_parse.c \
elm_code_test_text.c \
elm_code_test_widget.c \
elm_code_test_widget_selection.c \
elm_code_suite.c
elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \

View File

@ -19,6 +19,7 @@ static const struct {
{ "text", elm_code_test_text },
{ "basic", elm_code_test_basic },
{ "widget", elm_code_test_widget },
{ "widget_selection", elm_code_test_widget_selection },
};
START_TEST(elm_code_initialization)

View File

@ -11,5 +11,6 @@ void elm_code_test_basic(TCase *tc);
void elm_code_test_parse(TCase *tc);
void elm_code_test_text(TCase *tc);
void elm_code_test_widget(TCase *tc);
void elm_code_test_widget_selection(TCase *tc);
#endif /* _EDLM_CODE_SUITE_H */

View File

@ -0,0 +1,73 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "elm_code_suite.h"
#include "elm_code_widget_selection.h"
START_TEST (elm_code_test_widget_selection_set)
{
Elm_Code *code;
Elm_Code_File *file;
Elm_Code_Widget *widget;
Evas_Object *win;
elm_init(1, NULL);
code = elm_code_create();
file = elm_code_file_new(code);
elm_code_file_line_append(file, "test", 4, NULL);
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
widget = eo_add(ELM_CODE_WIDGET_CLASS, win,
elm_code_widget_code_set(code));
elm_code_widget_selection_start(widget, 1, 2);
elm_code_widget_selection_end(widget, 1, 3);
elm_code_widget_selection_clear(widget);
elm_code_free(code);
elm_shutdown();
}
END_TEST
START_TEST (elm_code_test_widget_selection_text_get)
{
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, "test", 4, NULL);
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
widget = eo_add(ELM_CODE_WIDGET_CLASS, win,
elm_code_widget_code_set(code));
ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));
elm_code_widget_selection_start(widget, 1, 2);
elm_code_widget_selection_end(widget, 1, 3);
selection = elm_code_widget_selection_text_get(widget);
ck_assert_str_eq("es", selection);
free(selection);
elm_code_widget_selection_clear(widget);
ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));
elm_code_free(code);
elm_shutdown();
}
END_TEST
void elm_code_test_widget_selection(TCase *tc)
{
tcase_add_test(tc, elm_code_test_widget_selection_set);
tcase_add_test(tc, elm_code_test_widget_selection_text_get);
}