[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30764] trunk/blender/source/blender/ editors/space_text/text_draw.c: [#23032] Bracket Highlighting in Text Space Fix [Patch to fix attached]

Campbell Barton ideasman42 at gmail.com
Mon Jul 26 20:38:12 CEST 2010


Revision: 30764
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30764
Author:   campbellbarton
Date:     2010-07-26 20:38:12 +0200 (Mon, 26 Jul 2010)

Log Message:
-----------
[#23032] Bracket Highlighting in Text Space Fix [Patch to fix attached]
from Justin Dailey (dail)

 from the tracker
 --- snip ---

In the text editor doing something like this:

print(":(")

When it goes to match the closing bracket, it will highlight the one in the string, not the first one. Also doing:

array["[index"]

will cause it to match the second [ with the closing one.

I have attached a patch to fix this issue. (See attached image to see correct highlighting)
It also works with triple quotes strings(ie """...""" or '''...''')

*Note* However, originally bracket highlighting always on even if syntax highlighting is off. The patch makes it so
it only highlights brackets when syntax highlighting is on (this is a side effect of doing the code this way, if it
was done any other way ALOT of code would have been needed to check for strings,triple quoted strings, escaped quotes,
and comments forwards and backwards). When highlighting matching brackets, the code checks the line's format string
to see if the char is in a string or comment to skip it. If syntax highlighting is turned off, the format string is
null and cannot be used,thus no bracket highlighting.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/text_draw.c

Modified: trunk/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_draw.c	2010-07-26 18:37:47 UTC (rev 30763)
+++ trunk/blender/source/blender/editors/space_text/text_draw.c	2010-07-26 18:38:12 UTC (rev 30764)
@@ -1132,7 +1132,8 @@
 	int viewc, viewl, offl, offc, x, y;
 	char ch;
 
-	if(!text->curl) return;
+	// showsyntax must be on or else the format string will be null
+	if(!text->curl || !st->showsyntax) return;
 
 	startl= text->curl;
 	startc= text->curc;
@@ -1146,24 +1147,30 @@
 	endc= -1;
 	find= -b;
 	stack= 0;
+	
+	/* Dont highlight backets if syntax HL is off or bracket in string or comment. */
+	if(!linep->format || linep->format[c] == 'l' || linep->format[c] == '#')
+		return;
 
 	if(b>0) {
 		/* opening bracket, search forward for close */
 		c++;
 		while(linep) {
 			while(c<linep->len) {
-				b= text_check_bracket(linep->line[c]);
-				if(b==find) {
-					if(stack==0) {
-						endl= linep;
-						endc= c;
-						break;
+				if(linep->format[c] != 'l' && linep->format[c] != '#') {
+					b= text_check_bracket(linep->line[c]);
+					if(b==find) {
+						if(stack==0) {
+							endl= linep;
+							endc= c;
+							break;
+						}
+						stack--;
 					}
-					stack--;
+					else if(b==-find) {
+						stack++;
+					}
 				}
-				else if(b==-find) {
-					stack++;
-				}
 				c++;
 			}
 			if(endl) break;
@@ -1176,18 +1183,20 @@
 		c--;
 		while(linep) {
 			while(c>=0) {
-				b= text_check_bracket(linep->line[c]);
-				if(b==find) {
-					if(stack==0) {
-						endl= linep;
-						endc= c;
-						break;
+				if(linep->format[c] != 'l' && linep->format[c] != '#') {
+					b= text_check_bracket(linep->line[c]);
+					if(b==find) {
+						if(stack==0) {
+							endl= linep;
+							endc= c;
+							break;
+						}
+						stack--;
 					}
-					stack--;
+					else if(b==-find) {
+						stack++;
+					}
 				}
-				else if(b==-find) {
-					stack++;
-				}
 				c--;
 			}
 			if(endl) break;





More information about the Bf-blender-cvs mailing list