forked from enlightenment/edi
elm_code: Support multi-line tokens
Adding a new token to each line it covers. Each token references the end line so newline behaviour can be set
This commit is contained in:
parent
dd9f96d2c0
commit
bbe671626e
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -248,28 +248,12 @@ _edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I
|
|||
}
|
||||
|
||||
#if HAVE_LIBCLANG
|
||||
static void
|
||||
_edi_line_color_remove(Edi_Editor *editor, unsigned int number)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_Line *line;
|
||||
|
||||
eo_do(editor->entry,
|
||||
code = elm_code_widget_code_get());
|
||||
line = elm_code_file_line_get(code->file, number);
|
||||
|
||||
eina_list_free(line->tokens);
|
||||
line->tokens = NULL;
|
||||
|
||||
eo_do(editor->entry,
|
||||
elm_code_widget_line_refresh(line));
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_range_color_set(Edi_Editor *editor, Edi_Range range, Elm_Code_Token_Type type)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_Line *line;
|
||||
Elm_Code_Line *line, *extra_line;
|
||||
int number;
|
||||
|
||||
eo_do(editor->entry,
|
||||
code = elm_code_widget_code_get());
|
||||
|
@ -277,9 +261,17 @@ _edi_range_color_set(Edi_Editor *editor, Edi_Range range, Elm_Code_Token_Type ty
|
|||
|
||||
ecore_thread_main_loop_begin();
|
||||
|
||||
elm_code_line_token_add(line, range.start.col, range.end.col - 1, type);
|
||||
elm_code_line_token_add(line, range.start.col, range.end.col - 1,
|
||||
range.end.line - range.start.line + 1, type);
|
||||
|
||||
eo_do(editor->entry,
|
||||
elm_code_widget_line_refresh(line));
|
||||
for (number = line->number + 1; number <= range.end.line; number++)
|
||||
{
|
||||
extra_line = elm_code_file_line_get(code->file, number);
|
||||
eo_do(editor->entry,
|
||||
elm_code_widget_line_refresh(extra_line));
|
||||
}
|
||||
|
||||
ecore_thread_main_loop_end();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue