Problems with cyrillic symbols in SynEditHighlighter.pas

Post Reply
Ta2i4
Posts: 3
Joined: 23 May 2008 01:23

Problems with cyrillic symbols in SynEditHighlighter.pas

Post by Ta2i4 » 06 Aug 2009 16:31

Please, fix function TSynCustomHighlighter.IsIdentChar in SynEditHighlighter.pas (Unicode SynEdit 2009-06-14 from CVS synedit.sourceforge.net).

Original code:

Code: Select all

function TSynCustomHighlighter.IsIdentChar(AChar: WideChar): Boolean;
begin
  case AChar of
    '_', '0'..'9', 'A'..'Z', 'a'..'z':
      Result := True;
    else
      Result := False;
  end;
end;
Procedure SynEdit1.ExecuteCommand(198, 'A', @SynEdit1.Lines) (select word at caret) not works for cyrillic words with this code, when using highlighters. This procedure works, when SynEdit1.Highlighter := nil;

My code to fix the bug with cyrillic symbols/words:

Code: Select all

function TSynCustomHighlighter.IsIdentChar(AChar: WideChar): Boolean;
begin
  Result := (AChar >= #33) and not IsWordBreakChar(AChar)
end;
Maybe, it is bad solution. I'm not good programmer.

PS: Sorry for my bad english.

Maël
Site Admin
Posts: 1129
Joined: 12 Mar 2005 14:15

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Post by Maël » 07 Aug 2009 14:25

But most programming languages just allows these characters. Changing this would cause identifiers to be valid which aren't.

Ta2i4
Posts: 3
Joined: 23 May 2008 01:23

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Post by Ta2i4 » 08 Aug 2009 13:27

:( How to fix this problem? I don't know :(

Maël
Site Admin
Posts: 1129
Joined: 12 Mar 2005 14:15

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Post by Maël » 08 Aug 2009 16:05

The problem is that in SynEdit a word=identifier.

To get the behavior you want you would have to replace calls to IsIdentChar with "not (IsWhiteChar(AChar) or IsWordBreakChar(AChar))" in all procedures in SynEdit.pas.
However this would break the assumption mentioned above. I haven't designed SynEdit like this, and I am wary of changing it as it might break other peoples code.

Maël
Site Admin
Posts: 1129
Joined: 12 Mar 2005 14:15

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Post by Maël » 08 Aug 2009 16:08

If you know that a specific highlighter (or better say the programming language) accepts cyrillic characters then you can override IsIdentChar of this specific highlighter to make it accept them. You could use something like SynIsCharAlpha or SynIsCharAlphaNumeric to identify valid characters (but check the documentation of that language to know what characters are really accepted).

Post Reply