ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=55d20b1cbc57bdd68fd1ed8aa000744fa115bcee

commit 55d20b1cbc57bdd68fd1ed8aa000744fa115bcee
Author: Andy Williams <a...@andywilliams.me>
Date:   Sun Sep 20 10:39:33 2015 +0100

    [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.
---
 elm_code/src/lib/elm_code_line.c          | 59 ++++++++++++++++++++++++++-----
 elm_code/src/lib/elm_code_line.h          |  2 +-
 elm_code/src/lib/widget/elm_code_widget.c |  2 +-
 3 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/elm_code/src/lib/elm_code_line.c b/elm_code/src/lib/elm_code_line.c
index ae921f7..c8b03b7 100644
--- a/elm_code/src/lib/elm_code_line.c
+++ b/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/elm_code/src/lib/elm_code_line.h b/elm_code/src/lib/elm_code_line.h
index 822cbea..f9492aa 100644
--- a/elm_code/src/lib/elm_code_line.h
+++ b/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/elm_code/src/lib/widget/elm_code_widget.c 
b/elm_code/src/lib/widget/elm_code_widget.c
index 8b1a7a2..71867e5 100644
--- a/elm_code/src/lib/widget/elm_code_widget.c
+++ b/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);
 

-- 


Reply via email to