[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38722] trunk/blender/source/blender/ blenkernel/intern/text.c: Fix #28087: Opening files in the text editor ignores the last newline '\n'

Sergey Sharybin g.ulairi at gmail.com
Tue Jul 26 10:13:28 CEST 2011


Revision: 38722
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38722
Author:   nazgul
Date:     2011-07-26 08:13:27 +0000 (Tue, 26 Jul 2011)
Log Message:
-----------
Fix #28087: Opening files in the text editor ignores the last newline '\n'

It was tricky conversion of file buffer to text lines. Should work fine now.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/text.c

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2011-07-26 07:41:14 UTC (rev 38721)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2011-07-26 08:13:27 UTC (rev 38722)
@@ -400,7 +400,13 @@
 		llen++;
 	}
 
-	if (llen!=0 || ta->nlines==0) {
+	/* create new line in cases:
+	   - rest of line (if last line in file hasn't got \n terminator).
+	     in this case content of such line would be used to fill text line buffer
+	   - file is empty. in this case new line is needed to start editing from.
+	   - last characted in buffer is \n. in this case new line is needed to
+	     deal with newline at end of file. (see [#28087]) (sergey) */
+	if (llen!=0 || ta->nlines==0 || buffer[len-1]=='\n') {
 		tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
 		tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
 		tmp->format= NULL;




More information about the Bf-blender-cvs mailing list