forked from enlightenment/efl
editor: correctly paste multiline windows text
This commit is contained in:
parent
ee9cec7ddd
commit
a5e1f82382
|
@ -220,15 +220,17 @@ elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop)
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
elm_code_text_newlinenpos(const char *text, unsigned int length)
|
elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen)
|
||||||
{
|
{
|
||||||
int lfpos, crpos;
|
int lfpos, crpos;
|
||||||
int check;
|
int check;
|
||||||
|
|
||||||
|
if (nllen)
|
||||||
|
*nllen = 1;
|
||||||
lfpos = elm_code_text_strnpos(text, length, "\n", 0);
|
lfpos = elm_code_text_strnpos(text, length, "\n", 0);
|
||||||
check = length;
|
check = length;
|
||||||
if (lfpos != ELM_CODE_TEXT_NOT_FOUND)
|
if (lfpos != ELM_CODE_TEXT_NOT_FOUND)
|
||||||
check = lfpos;
|
check = lfpos + 1;
|
||||||
crpos = elm_code_text_strnpos(text, check, "\r", 0);
|
crpos = elm_code_text_strnpos(text, check, "\r", 0);
|
||||||
|
|
||||||
if (lfpos == ELM_CODE_TEXT_NOT_FOUND && crpos == ELM_CODE_TEXT_NOT_FOUND)
|
if (lfpos == ELM_CODE_TEXT_NOT_FOUND && crpos == ELM_CODE_TEXT_NOT_FOUND)
|
||||||
|
@ -238,6 +240,9 @@ elm_code_text_newlinenpos(const char *text, unsigned int length)
|
||||||
return lfpos;
|
return lfpos;
|
||||||
if (lfpos == ELM_CODE_TEXT_NOT_FOUND)
|
if (lfpos == ELM_CODE_TEXT_NOT_FOUND)
|
||||||
return crpos;
|
return crpos;
|
||||||
|
|
||||||
|
if (nllen)
|
||||||
|
*nllen = 2;
|
||||||
if (lfpos < crpos)
|
if (lfpos < crpos)
|
||||||
return lfpos;
|
return lfpos;
|
||||||
return crpos;
|
return crpos;
|
||||||
|
|
|
@ -52,7 +52,7 @@ EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsi
|
||||||
|
|
||||||
EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char *search, int offset);
|
EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char *search, int offset);
|
||||||
|
|
||||||
EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length);
|
EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen);
|
||||||
|
|
||||||
EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int length, unsigned int tabstop);
|
EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int length, unsigned int tabstop);
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,7 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co
|
||||||
Elm_Code_Line *line;
|
Elm_Code_Line *line;
|
||||||
unsigned int position, newrow, remain;
|
unsigned int position, newrow, remain;
|
||||||
int nlpos;
|
int nlpos;
|
||||||
|
short nllen;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
line = elm_code_file_line_get(code->file, row);
|
line = elm_code_file_line_get(code->file, row);
|
||||||
|
@ -319,15 +320,15 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co
|
||||||
newrow = row;
|
newrow = row;
|
||||||
ptr = (char *)text;
|
ptr = (char *)text;
|
||||||
remain = len;
|
remain = len;
|
||||||
while ((nlpos = elm_code_text_newlinenpos(ptr, remain)) != ELM_CODE_TEXT_NOT_FOUND)
|
while ((nlpos = elm_code_text_newlinenpos(ptr, remain, &nllen)) != ELM_CODE_TEXT_NOT_FOUND)
|
||||||
{
|
{
|
||||||
if (newrow == row)
|
if (newrow == row)
|
||||||
_selection_paste_single(widget, pd, code, col, row, text, nlpos);
|
_selection_paste_single(widget, pd, code, col, row, text, nlpos);
|
||||||
else
|
else
|
||||||
elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL);
|
elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL);
|
||||||
|
|
||||||
remain -= nlpos + 1; // TODO make this adapt to windows lengths (length param to newlinenpos)
|
remain -= nlpos + nllen;
|
||||||
ptr += nlpos + 1;
|
ptr += nlpos + nllen;
|
||||||
newrow++;
|
newrow++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +356,7 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data
|
||||||
code = elm_code_widget_code_get(),
|
code = elm_code_widget_code_get(),
|
||||||
elm_code_widget_cursor_position_get(&col, &row));
|
elm_code_widget_cursor_position_get(&col, &row));
|
||||||
|
|
||||||
if (elm_code_text_newlinenpos(ev->data, ev->len) == ELM_CODE_TEXT_NOT_FOUND)
|
if (elm_code_text_newlinenpos(ev->data, ev->len, NULL) == ELM_CODE_TEXT_NOT_FOUND)
|
||||||
_selection_paste_single(widget, pd, code, col, row, ev->data, ev->len - 1);
|
_selection_paste_single(widget, pd, code, col, row, ev->data, ev->len - 1);
|
||||||
else
|
else
|
||||||
_selection_paste_multi(widget, pd, code, col, row, ev->data, ev->len - 1);
|
_selection_paste_multi(widget, pd, code, col, row, ev->data, ev->len - 1);
|
||||||
|
|
Loading…
Reference in New Issue