diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index d3fd2cbd0d..97fbb09018 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -55,7 +55,7 @@ _elm_code_test_line_done_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, line = (Elm_Code_Line *)event_info; if (line->number == 1) - elm_code_line_token_add(line, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 14, 21, 1, ELM_CODE_TOKEN_TYPE_COMMENT); else if (line->number == 4) line->status = ELM_CODE_STATUS_TYPE_ERROR; diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index cc24dcd498..c73f71fc4c 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -6,13 +6,14 @@ #include "elm_code_private.h" -static Elm_Code_Line *_elm_code_blank_create(int line, void *data) +static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int line, void *data) { Elm_Code_Line *ecl; ecl = calloc(1, sizeof(Elm_Code_Line)); if (!ecl) return NULL; + ecl->file = file; ecl->number = line; ecl->status = ELM_CODE_STATUS_TYPE_DEFAULT; ecl->data = data; @@ -24,7 +25,7 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con { Elm_Code_Line *line; - line = _elm_code_blank_create(row, data); + line = _elm_code_file_line_blank_create(file, row, data); if (!line) return; if (mapped) @@ -88,7 +89,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ while (lastindex < line->index - 1) { - ecl = _elm_code_blank_create(++lastindex, NULL); + ecl = _elm_code_file_line_blank_create(ret, ++lastindex, NULL); if (!ecl) continue; ret->lines = eina_list_append(ret->lines, ecl); diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index 6a7af560be..117227b22a 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -26,19 +26,32 @@ EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type sta line->status = status; } -EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type) +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, + Elm_Code_Token_Type type) { Elm_Code_Token *tok; + unsigned int end_line; + Elm_Code_Line *next_line; if (!line) return; tok = calloc(1, sizeof(Elm_Code_Token)); + end_line = line->number; + if (lines > 1) + end_line += lines - 1; + tok->start = start; tok->end = end; + tok->end_line = end_line; tok->type = type; line->tokens = eina_list_append(line->tokens, tok); -} + if (end_line > line->number) + { + next_line = elm_code_file_line_get(line->file, line->number + 1); + elm_code_line_token_add(next_line, 1, end, lines - 1, type); + } +} diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 339c96691d..5a66f73fe7 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -13,6 +13,7 @@ extern "C" { typedef struct _Elm_Code_Token { int start, end; + unsigned int end_line; Elm_Code_Token_Type type; @@ -20,6 +21,8 @@ typedef struct _Elm_Code_Token typedef struct _Elm_Code_Line { + Elm_Code_File *file; + const char *content; int length; unsigned int number; @@ -45,7 +48,7 @@ EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length); EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status); -EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type); +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type); /** * @} diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index fd4b09a58b..eb731e281e 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -116,7 +116,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c { Eina_List *item; Elm_Code_Token *token; - int start, length, offset; + int start, end, length, offset; offset = elm_code_widget_text_left_gutter_width_get(widget) - 1; start = offset + 1; @@ -124,13 +124,16 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c EINA_LIST_FOREACH(line->tokens, item, token) { - - _elm_code_widget_fill_line_token(cells, count, start, token->start + offset, ELM_CODE_TOKEN_TYPE_DEFAULT); + if (token->start > start) + _elm_code_widget_fill_line_token(cells, count, start, token->start + offset, ELM_CODE_TOKEN_TYPE_DEFAULT); // TODO handle a token starting before the previous finishes - _elm_code_widget_fill_line_token(cells, count, token->start + offset, token->end + offset, token->type); + end = token->end; + if (token->end_line > line->number) + end = count; + _elm_code_widget_fill_line_token(cells, count, token->start + offset, end + offset, token->type); - start = token->end + offset + 1; + start = end + offset + 1; } _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); diff --git a/legacy/elm_code/src/tests/elm_code_file_test_memory.c b/legacy/elm_code/src/tests/elm_code_file_test_memory.c index e4b3e3721f..b82ce2eda2 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/src/tests/elm_code_file_test_memory.c @@ -29,7 +29,7 @@ START_TEST (elm_code_file_memory_tokens) elm_code_file_line_append(file, "a line", 6, NULL); line = elm_code_file_line_get(file, 1); - elm_code_line_token_add(line, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT); ck_assert_uint_eq(1, eina_list_count(line->tokens)); elm_code_free(code); } diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c index 2836bb4c44..e30c890b92 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget.c @@ -26,8 +26,8 @@ START_TEST (elm_code_widget_token_render_simple_test) line = elm_code_file_line_get(file, 1); length = line->length; - elm_code_line_token_add(line, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_line_token_add(line, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 6+1, 17+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 21+1, 22+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); _elm_code_widget_fill_line_tokens(NULL, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1);