[highlight] Merge highlight tokens on line merge
Instead of blanking colours we append them as with the content.
This commit is contained in:
parent
55d20b1cbc
commit
2297e250bc
|
@ -83,6 +83,68 @@ EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position)
|
|||
free(content);
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_line_merge_into(Elm_Code_Line *line1, Elm_Code_Line *line2)
|
||||
{
|
||||
Eina_List *tokens1, *tokens2;
|
||||
Elm_Code_Token *token;
|
||||
const char *text1, *text2;
|
||||
char *newtext;
|
||||
unsigned int length1, length2;
|
||||
|
||||
text1 = elm_code_line_text_get(line1, &length1);
|
||||
text2 = elm_code_line_text_get(line2, &length2);
|
||||
|
||||
newtext = malloc(sizeof(char) * (length1 + length2 + 1));
|
||||
snprintf(newtext, length1 + 1, "%s", text1);
|
||||
snprintf(newtext + length1, length2 + 1, "%s", text2);
|
||||
|
||||
tokens1 = line1->tokens;
|
||||
line1->tokens = NULL;
|
||||
tokens2 = line2->tokens;
|
||||
line2->tokens = NULL;
|
||||
elm_code_file_line_remove(line2->file, line2->number);
|
||||
elm_code_line_text_set(line1, newtext, length1 + length2);
|
||||
|
||||
EINA_LIST_FREE(tokens1, token)
|
||||
{
|
||||
token->continues = EINA_FALSE;
|
||||
line1->tokens = eina_list_append(line1->tokens, token);
|
||||
}
|
||||
EINA_LIST_FREE(tokens2, token)
|
||||
{
|
||||
token->start += length1;
|
||||
token->end += length1;
|
||||
|
||||
line1->tokens = eina_list_append(line1->tokens, token);
|
||||
}
|
||||
|
||||
elm_code_callback_fire(line1->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line1);
|
||||
free(newtext);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_code_line_merge_up(Elm_Code_Line *line)
|
||||
{
|
||||
Elm_Code_Line *other;
|
||||
|
||||
other = elm_code_file_line_get(line->file, line->number - 1);
|
||||
|
||||
if (other)
|
||||
_elm_code_line_merge_into(other, line);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_code_line_merge_down(Elm_Code_Line *line)
|
||||
{
|
||||
Elm_Code_Line *other;
|
||||
|
||||
other = elm_code_file_line_get(line->file, line->number + 1);
|
||||
|
||||
if (other)
|
||||
_elm_code_line_merge_into(line, other);
|
||||
}
|
||||
|
||||
EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status)
|
||||
{
|
||||
if (!line)
|
||||
|
|
|
@ -45,8 +45,43 @@ EAPI void elm_code_line_free(Elm_Code_Line *line);
|
|||
* Functions for changing the content of lines in an Elm_Code_File
|
||||
*/
|
||||
|
||||
/**
|
||||
* Split the given line into two at the specified character position.
|
||||
* The additional line will be inserted into the file immediately below the specified line.
|
||||
*
|
||||
* @param line The line to split
|
||||
* @param position The character position to split at
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position);
|
||||
|
||||
/**
|
||||
* Merge the specified line with the line above.
|
||||
* The content of the specified line will be added to the end of the previous line.
|
||||
* The specified line will then be removed from the file.
|
||||
*
|
||||
* If there is no previous line this method does nothing.
|
||||
*
|
||||
* @param line The line to merge with the previous line.
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
EAPI void elm_code_line_merge_up(Elm_Code_Line *line);
|
||||
|
||||
/**
|
||||
* Merge the specified line with the line below.
|
||||
* The content of the specified line will have the contents of the next line added to the end.
|
||||
* The next line will then be removed from the file.
|
||||
*
|
||||
* If there is no next line this method does nothing.
|
||||
*
|
||||
* @param line The line to merge with the next line.
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
EAPI void elm_code_line_merge_down(Elm_Code_Line *line);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
|
|
@ -1038,12 +1038,8 @@ static void
|
|||
_elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_Line *line, *otherline;
|
||||
unsigned int row, col, position;
|
||||
|
||||
const char *text1, *text2;
|
||||
char *newtext;
|
||||
unsigned int length1, length2;
|
||||
Elm_Code_Line *line, *oldline;
|
||||
unsigned int row, col, oldlength, position;
|
||||
|
||||
eo_do(widget,
|
||||
code = elm_obj_code_widget_code_get(),
|
||||
|
@ -1052,29 +1048,15 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline)
|
|||
|
||||
if (nextline)
|
||||
{
|
||||
otherline = elm_code_file_line_get(code->file, row + 1);
|
||||
text1 = elm_code_line_text_get(line, &length1);
|
||||
text2 = elm_code_line_text_get(otherline, &length2);
|
||||
elm_code_line_merge_down(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
otherline = elm_code_file_line_get(code->file, row - 1);
|
||||
text1 = elm_code_line_text_get(otherline, &length1);
|
||||
text2 = elm_code_line_text_get(line, &length2);
|
||||
}
|
||||
oldline = elm_code_file_line_get(code->file, row - 1);
|
||||
elm_code_line_text_get(oldline, &oldlength);
|
||||
elm_code_line_merge_up(line);
|
||||
|
||||
newtext = malloc(sizeof(char) * (length1 + length2 + 1));
|
||||
snprintf(newtext, length1 + 1, "%s", text1);
|
||||
snprintf(newtext + length1, length2 + 1, "%s", text2);
|
||||
|
||||
// TODO we need to merge tokens from these lines (move this to elm_code_line?)
|
||||
elm_code_file_line_remove(code->file, otherline->number);
|
||||
elm_code_line_text_set(line, newtext, length1 + length2);
|
||||
|
||||
free(newtext);
|
||||
if (!nextline)
|
||||
{
|
||||
position = elm_code_widget_line_text_column_width_to_position(widget, line, length1);
|
||||
position = elm_code_widget_line_text_column_width_to_position(widget, oldline, oldlength);
|
||||
|
||||
eo_do(widget,
|
||||
elm_obj_code_widget_cursor_position_set(position, row - 1));
|
||||
|
|
Loading…
Reference in New Issue