From 661d6ff7e5f5135c35029e87ce95029449b6c52c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 20 Apr 2011 07:44:42 +0000 Subject: 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. --- source/blender/blenkernel/BKE_text.h | 1 + source/blender/blenkernel/intern/text.c | 44 ++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index a6b98b8ea88..136ce416037 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -89,6 +89,7 @@ void txt_split_curline (struct Text *text); void txt_backspace_char (struct Text *text); void txt_backspace_word (struct Text *text); 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); void txt_export_to_object (struct Text *text); void txt_export_to_objects(struct Text *text); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index e7b85ec9b17..5a8106b23e3 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1348,9 +1348,19 @@ char *txt_sel_to_buf (Text *text) 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) { - int i=0, l=0, j, u, len; + int i=0, l=0, j, u, len, lineno= -1, count= 0; TextLine *add; 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 */ while (in_buffer[i] && in_buffer[i]!='\n') { - txt_add_char(text, in_buffer[i]); + txt_add_raw_char(text, in_buffer[i]); i++; } @@ -1375,6 +1385,7 @@ void txt_insert_buf(Text *text, const char *in_buffer) /* Read as many full lines as we can */ len= strlen(in_buffer); + lineno= txt_get_span(text->lines.first, text->curl); while (ilines, text->curl, add); i++; + count++; } else { + if(count) { + txt_shift_markers(text, lineno, count); + count= 0; + } + for (j= i-l; jflags & TXT_TABSTOSPACES) { + if (add == '\t' && replace_tabs) { txt_convert_tab_to_spaces(text); return 1; } @@ -2428,6 +2450,16 @@ int txt_add_char (Text *text, char add) 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) { txt_delete_sel(text); -- cgit v1.2.3