diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-07-26 22:38:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-07-26 22:38:12 +0400 |
commit | c0898bbf48ecf7c9260489d93c37f6f4fbd7b71d (patch) | |
tree | 316aeb4fff577a458e1b6a882c266a82bba3efab | |
parent | 8fb499c34f8dd9bd38c73c88cf2e588aae854606 (diff) |
[#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.
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 873deb30511..8570965bb03 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1132,7 +1132,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar) 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,23 +1147,29 @@ static void draw_brackets(SpaceText *st, ARegion *ar) 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--; + } + else if(b==-find) { + stack++; } - stack--; - } - else if(b==-find) { - stack++; } c++; } @@ -1176,17 +1183,19 @@ static void draw_brackets(SpaceText *st, ARegion *ar) 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--; + } + else if(b==-find) { + stack++; } - stack--; - } - else if(b==-find) { - stack++; } c--; } |