Page 1 of 1

Problems with cyrillic symbols in SynEditHighlighter.pas

Posted: 06 Aug 2009 16:31
by Ta2i4
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.

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Posted: 07 Aug 2009 14:25
by Maël
But most programming languages just allows these characters. Changing this would cause identifiers to be valid which aren't.

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Posted: 08 Aug 2009 13:27
by Ta2i4
:( How to fix this problem? I don't know :(

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Posted: 08 Aug 2009 16:05
by Maël
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.

Re: Problems with cyrillic symbols in SynEditHighlighter.pas

Posted: 08 Aug 2009 16:08
by Maël
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).