diff options
author | Andy Williams <andy@andywilliams.me> | 2015-09-20 10:39:33 +0100 |
---|---|---|
committer | Andy Williams <andy@andywilliams.me> | 2015-09-20 10:39:33 +0100 |
commit | d1e3481b32ccb86868585947140f031f3b8c007d (patch) | |
tree | 4698bf8a8636ac57c27184aea56ad1e3a5c54f37 | |
parent | 65a32dddd1fb7f01e65a322ba4499c6e8de8dde6 (diff) | |
download | efl-d1e3481b32ccb86868585947140f031f3b8c007d.tar.gz |
[highlight] Split highlight tokens on line split
Instead of blanking colours work out what to do with them.
Refactor the token carry over to simply note if there's a continuation.
-rw-r--r-- | legacy/elm_code/src/lib/elm_code_line.c | 59 | ||||
-rw-r--r-- | legacy/elm_code/src/lib/elm_code_line.h | 2 | ||||
-rw-r--r-- | legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 |
3 files changed, 53 insertions, 10 deletions
diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index ae921f7751..c8b03b7199 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -20,9 +20,51 @@ elm_code_line_free(Elm_Code_Line *line) free(line); } +static void +_elm_code_line_tokens_split_at(Elm_Code_Line *oldline, Elm_Code_Line *newline, + Eina_List *tokens, int position) +{ + Eina_List *item, *next; + Elm_Code_Token *token, *newtoken; + + EINA_LIST_FOREACH_SAFE(tokens, item, next, token) + { + if (!token->continues && token->end < position) + { + oldline->tokens = eina_list_append(oldline->tokens, token); + continue; + } + if (token->start >= position) + { + token->start -= position; + token->end -= position; + newline->tokens = eina_list_append(newline->tokens, token); + continue; + } + + if (token->continues) + elm_code_line_token_add(newline, 0, token->end, 1, token->type); + else + { + elm_code_line_token_add(newline, 0, token->end - position, 1, token->type); + token->end = position - 1; + } + + newtoken = eina_list_data_get(newline->tokens); + newtoken->continues = token->continues; + token->continues = EINA_TRUE; + oldline->tokens = eina_list_append(oldline->tokens, token); + } + + elm_code_callback_fire(oldline->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, oldline); + elm_code_callback_fire(newline->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, newline); +} + EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position) { Elm_Code_Line *newline; + Elm_Code_Token *token EINA_UNUSED; + Eina_List *tokens; char *content; unsigned int length; @@ -30,11 +72,14 @@ EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position) content = strndup(content, length); elm_code_file_line_insert(line->file, line->number + 1, "", 0, NULL); newline = elm_code_file_line_get(line->file, line->number + 1); -// TODO we need to split tokens from these lines + tokens = line->tokens; + line->tokens = NULL; elm_code_line_text_set(newline, content + position, length - position); elm_code_line_text_set(line, content, position); + _elm_code_line_tokens_split_at(line, newline, tokens, position); + EINA_LIST_FREE(tokens, token) {} // don't free tokens, we re-used them free(content); } @@ -61,7 +106,6 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l Elm_Code_Token_Type type) { Elm_Code_Token *tok; - unsigned int end_line; Elm_Code_Line *next_line; if (!line) @@ -69,18 +113,14 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l 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->continues = lines > 1; tok->type = type; line->tokens = eina_list_append(line->tokens, tok); - if (end_line > line->number) + if (lines > 1) { next_line = elm_code_file_line_get(line->file, line->number + 1); elm_code_line_token_add(next_line, 0, end, lines - 1, type); @@ -91,6 +131,9 @@ EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line) { Elm_Code_Token *token; + if (!line->tokens) + return; + EINA_LIST_FREE(line->tokens, token) free(token); line->tokens = NULL; diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 822cbea642..f9492aafee 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -13,7 +13,7 @@ extern "C" { typedef struct _Elm_Code_Token { int start, end; - unsigned int end_line; + Eina_Bool continues; Elm_Code_Token_Type type; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 8b1a7a2c34..71867e570e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -195,7 +195,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c // TODO handle a token starting before the previous finishes end = token_end_col; - if (token->end_line > line->number) + if (token->continues) end = length + offset; _elm_code_widget_fill_line_token(cells, count, token_start_col, end, token->type); |