Fix #27014: ctrl-A, ctrl-C, ctrl-V breaks formatting of script
This bug was caused by tabs->spaces conversion. Change pate-ing logic to paste buffer AS-IS (without any conversions). This commit also fixes undo-ing block deletion which contains tabs when "Tabs as spaces" is toggled on. Also, markes shouldn't be moved after pasteing new buffer.
This commit is contained in:
@@ -89,6 +89,7 @@ void txt_split_curline (struct Text *text);
|
|||||||
void txt_backspace_char (struct Text *text);
|
void txt_backspace_char (struct Text *text);
|
||||||
void txt_backspace_word (struct Text *text);
|
void txt_backspace_word (struct Text *text);
|
||||||
int txt_add_char (struct Text *text, char add);
|
int txt_add_char (struct Text *text, char add);
|
||||||
|
int txt_add_raw_char (struct Text *text, char add);
|
||||||
int txt_replace_char (struct Text *text, char add);
|
int txt_replace_char (struct Text *text, char add);
|
||||||
void txt_export_to_object (struct Text *text);
|
void txt_export_to_object (struct Text *text);
|
||||||
void txt_export_to_objects(struct Text *text);
|
void txt_export_to_objects(struct Text *text);
|
||||||
|
@@ -1348,9 +1348,19 @@ char *txt_sel_to_buf (Text *text)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void txt_shift_markers(Text *text, int lineno, int count)
|
||||||
|
{
|
||||||
|
TextMarker *marker;
|
||||||
|
|
||||||
|
for (marker=text->markers.first; marker; marker= marker->next)
|
||||||
|
if (marker->lineno>=lineno) {
|
||||||
|
marker->lineno+= count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void txt_insert_buf(Text *text, const char *in_buffer)
|
void txt_insert_buf(Text *text, const char *in_buffer)
|
||||||
{
|
{
|
||||||
int i=0, l=0, j, u, len;
|
int i=0, l=0, j, u, len, lineno= -1, count= 0;
|
||||||
TextLine *add;
|
TextLine *add;
|
||||||
|
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
@@ -1365,7 +1375,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
|
|||||||
|
|
||||||
/* Read the first line (or as close as possible */
|
/* Read the first line (or as close as possible */
|
||||||
while (in_buffer[i] && in_buffer[i]!='\n') {
|
while (in_buffer[i] && in_buffer[i]!='\n') {
|
||||||
txt_add_char(text, in_buffer[i]);
|
txt_add_raw_char(text, in_buffer[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1375,6 +1385,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
|
|||||||
|
|
||||||
/* Read as many full lines as we can */
|
/* Read as many full lines as we can */
|
||||||
len= strlen(in_buffer);
|
len= strlen(in_buffer);
|
||||||
|
lineno= txt_get_span(text->lines.first, text->curl);
|
||||||
|
|
||||||
while (i<len) {
|
while (i<len) {
|
||||||
l=0;
|
l=0;
|
||||||
@@ -1387,14 +1398,25 @@ void txt_insert_buf(Text *text, const char *in_buffer)
|
|||||||
add= txt_new_linen(in_buffer +(i-l), l);
|
add= txt_new_linen(in_buffer +(i-l), l);
|
||||||
BLI_insertlinkbefore(&text->lines, text->curl, add);
|
BLI_insertlinkbefore(&text->lines, text->curl, add);
|
||||||
i++;
|
i++;
|
||||||
|
count++;
|
||||||
} else {
|
} else {
|
||||||
|
if(count) {
|
||||||
|
txt_shift_markers(text, lineno, count);
|
||||||
|
count= 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (j= i-l; j<i && j<(int)strlen(in_buffer); j++) {
|
for (j= i-l; j<i && j<(int)strlen(in_buffer); j++) {
|
||||||
txt_add_char(text, in_buffer[j]);
|
txt_add_raw_char(text, in_buffer[j]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count) {
|
||||||
|
txt_shift_markers(text, lineno, count);
|
||||||
|
count= 0;
|
||||||
|
}
|
||||||
|
|
||||||
undoing= u;
|
undoing= u;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2375,7 +2397,7 @@ static void txt_convert_tab_to_spaces (Text *text)
|
|||||||
txt_insert_buf(text, sb);
|
txt_insert_buf(text, sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int txt_add_char (Text *text, char add)
|
static int txt_add_char_intern (Text *text, char add, int replace_tabs)
|
||||||
{
|
{
|
||||||
int len, lineno;
|
int len, lineno;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
@@ -2390,7 +2412,7 @@ int txt_add_char (Text *text, char add)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* insert spaces rather then tabs */
|
/* insert spaces rather then tabs */
|
||||||
if (add == '\t' && text->flags & TXT_TABSTOSPACES) {
|
if (add == '\t' && replace_tabs) {
|
||||||
txt_convert_tab_to_spaces(text);
|
txt_convert_tab_to_spaces(text);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -2428,6 +2450,16 @@ int txt_add_char (Text *text, char add)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int txt_add_char (Text *text, char add)
|
||||||
|
{
|
||||||
|
return txt_add_char_intern(text, add, text->flags & TXT_TABSTOSPACES);
|
||||||
|
}
|
||||||
|
|
||||||
|
int txt_add_raw_char (Text *text, char add)
|
||||||
|
{
|
||||||
|
return txt_add_char_intern(text, add, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void txt_delete_selected(Text *text)
|
void txt_delete_selected(Text *text)
|
||||||
{
|
{
|
||||||
txt_delete_sel(text);
|
txt_delete_sel(text);
|
||||||
|
Reference in New Issue
Block a user