[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.
This commit is contained in:
Andy Williams 2015-09-20 10:39:33 +01:00
parent 65a32dddd1
commit d1e3481b32
3 changed files with 53 additions and 10 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);