Recent

Author Topic: [SOLVED] SynEdit: brtacket matching problem  (Read 3171 times)

Henppy

  • Jr. Member
  • **
  • Posts: 60
[SOLVED] SynEdit: brtacket matching problem
« on: January 14, 2014, 03:36:48 am »
Okay, first of all I want to say that I know I'm annoying and that I really appreciate the help you guys are giving me, I really do.

So, to continue to annoy you with my petty problems. I am having an issue with my custom highlighter. I've been trying to solve this for the last 5 hours and I have no clue.

What I have:

- Set the Editor.BracketMatchColor to what I want.
- Set BrackethighlightStyle := sbhsBoth.
- Set Editor.Options := [eoBracketHighlight + morestuff].
- Pretty much clone TSynHighlighterAny.

What doesn't work:

The braces are highlighted only if the type of token inside and to the right of the braces is the same. For example with "(x)x" both parenthesis are underlined, because of the "x" in both places. With "(1)x" it doesn't work and only one parenthesis is underlined, because "x" is an identifier en "1" is a number. Yes, I kid you not.

Now, I don't expect you to be able to tell me what the problem is (at least you have some kind of crystal ball in which case, be my guest :D), but does anybody have any idea about what should I look for? Maybe it happened to you in the past and you have some suggestions to troubleshoot this.

As I said, I more or less copied the way TSynHighlighterAny works, I can't seem to find any difference between HLAny and mine that could cause this... But obviously something is lurking in the dark corners of my code like a demonic gobbling from hell. :)
« Last Edit: January 15, 2014, 03:27:48 am by Henppy »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11338
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit: brtacket matching problem
« Reply #1 on: January 14, 2014, 03:58:31 am »
Firs of all: I decide if and when I am annoyed. I am not.

What is the TokenKind your highlighter returns for the brackets?

It must be the same for both of the pair.
If ( is TkSomeStart, and ) is tkOtherEnd then there is no match.

In pascal for example
Code: [Select]
if (a = 'foo(.' ) ar (a = 'bar).' ) then

The brackets in code are tkSymbol (both), and in the string it is tkString.
So SynEdit matches the brackets in code, and for that it ignores them in the string.
Yet it also matches the 2 brackets in the 2 strings.

That way the matching does not need to know the rules what a string, or comment, or any other context is.

Henppy

  • Jr. Member
  • **
  • Posts: 60
Re: SynEdit: brtacket matching problem
« Reply #2 on: January 14, 2014, 04:02:39 am »
Thanks Martin, yes both parenthesis are "ttSymbol". I looked at the GetToken, GetTokenPos, GetTokenKind methods and they seem to be working perfectly. I also noticed a method called GetTokenID in THighlighterAny but couldn't understand what the use if it was and it's not present on TSynCustomhighlighter so I *assume* it has nothing to do with this.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11338
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit: brtacket matching problem
« Reply #3 on: January 14, 2014, 04:14:04 am »
Well then you need to debug:

line 8260 SynEdit.pp

function TCustomSynEdit.FindMatchingBracketLogical(LogicalStartBracket: TPoint;
  StartIncludeNeighborChars, MoveCaret, SelectBrackets, OnlyVisible: Boolean): TPoint;

Nested function (1st on top):
  function IsContextBracket: boolean;

calls:
        TokenPosList.X := fHighlighter.GetTokenPos + 1;
        TokenPosList.Attr := fHighlighter.GetTokenKind;

---
Befor that, the kind of the bracket at the caret is detected, by a call to
GetHighlighterAttriAtRowColEx

Stored in the local var: BracketKind
So check, if that is correct.

then check, what IsContextBracket gets.


Maybe the HL is one off? Though then the color would be too. Unless GetTokenEx returns different? Painting uses GetTokenEx.

It may be a 0 vs 1 based issue. Not sure what it should actually be.

It may even be that SynAny is wrong?

Henppy

  • Jr. Member
  • **
  • Posts: 60
Re: SynEdit: brtacket matching problem
« Reply #4 on: January 15, 2014, 03:27:29 am »
Thanks Martin!

It  took me 10 minutes to discover the problem now that I knew where to look at. As it turned out, GetTokenPos in my custom highlighter was returning the wrong value by one char.  A line I looked a hundred million times. :-[

 

TinyPortal © 2005-2018