In SynEdit there is a great PaintTransient to highlight matching brackets.
Ansi didn't highlight correctly but thats fixed, but now i found the same bug in the UniCode version and i can't get that one to work. I hope there is someone who can help me out with this problem.
Samplecode:
</html>
In PaintTransient it will only highlight the last bracket ">" instead of both "<" ">" brackets.
Logged In: YES
user_id=99702
Originator: NO
Unicode branch is currently unmaintained; the one and only developer of it, Maël Hörz, has not been working on it lately.
Logged In: YES
user_id=99702
Originator: NO
If a patch is provided, I might apply it.
Logged In: YES
user_id=726063
Originator: YES
Replace the procedure EditorPaintTransient with the code posted below see my additions marked with // Comment darksumon Dynamic Array
procedure TForm1.EditorPaintTransient(Sender: TObject; Canvas: TCanvas;
TransientType: TTransientType);
const AllBrackets = ['{','[','(','<','}',']',')','>'];
var Editor: TSynEdit;
OpenChars: array of Char; // Comment darksumon Dynamic Array
CloseChars: array of Char; // Comment darksumon Dynamic Array
function CharToPixels(P: TBufferCoord): TPoint;
begin
Result:=Editor.RowColumnToPixels(Editor.BufferToDisplayPos(P));
end;
var P: TBufferCoord;
Pix: TPoint;
D : TDisplayCoord;
S: String;
I: Integer;
Attri: TSynHighlighterAttributes;
start: Integer;
TmpCharA, TmpCharB: Char;
begin
if TSynEdit(Sender).SelAvail then exit;
Editor := TSynEdit(Sender);
// if you had a highlighter that used a markup language, like html or
xml, then you would want to highlight
// the greater and less than signs as well as illustrated below
if (Editor.Highlighter = SynHTMLSyn1) or (Editor.Highlighter =
SynXMLSyn1) then
begin
// Comment darksumon In case of HTML increase array length.
setlength(OpenChars,4);
setlength(CloseChars,4);
end
else
begin
// Comment darksumon not HTML then keep array at length 3
setlength(OpenChars,3);
setlength(CloseChars,3);
end;
// Comment darksumon high(OpenChars) makes it all dynamic and the right
chars will be included.
for i := 0 to high(OpenChars) do
begin
case i of
0: begin OpenChars[i] := '('; CloseChars[i] := ')'; end;
1: begin OpenChars[i] := '{'; CloseChars[i] := '}'; end;
2: begin OpenChars[i] := '['; CloseChars[i] := ']'; end;
3: begin OpenChars[i] := '<'; CloseChars[i] := '>'; end;
end;
end;
P := Editor.CaretXY;
D := Editor.DisplayXY;
Start := Editor.SelStart;
if (Start > 0) and (Start <= length(Editor.Text)) then
TmpCharA := Editor.Text[Start]
else TmpCharA := #0;
if (Start < length(Editor.Text)) then
TmpCharB := Editor.Text[Start + 1]
else TmpCharB := #0;
if not(TmpCharA in AllBrackets) and not(TmpCharB in AllBrackets) then
exit;
S := TmpCharB;
if not(TmpCharB in AllBrackets) then
begin
P.Char := P.Char - 1;
S := TmpCharA;
end;
Editor.GetHighlighterAttriAtRowCol(P, S, Attri);
if (Editor.Highlighter.SymbolAttribute = Attri) then
begin
for i := low(OpenChars) to High(OpenChars) do
begin
if (S = OpenChars[i]) or (S = CloseChars[i]) then
begin
Pix := CharToPixels(P);
Editor.Canvas.Brush.Style := bsSolid;//Clear;
Editor.Canvas.Font.Assign(Editor.Font);
Editor.Canvas.Font.Style := Attri.Style;
if (TransientType = ttAfter) then
begin
Editor.Canvas.Font.Color := FBracketFG;
Editor.Canvas.Brush.Color := FBracketBG;
end else begin
Editor.Canvas.Font.Color := Attri.Foreground;
Editor.Canvas.Brush.Color := Attri.Background;
end;
if Editor.Canvas.Font.Color = clNone then
Editor.Canvas.Font.Color := Editor.Font.Color;
if Editor.Canvas.Brush.Color = clNone then
Editor.Canvas.Brush.Color := Editor.Color;
Editor.Canvas.TextOut(Pix.X, Pix.Y, S);
P := Editor.GetMatchingBracketEx(P);
if (P.Char > 0) and (P.Line > 0) then
begin
Pix := CharToPixels(P);
if Pix.X > Editor.Gutter.Width then
begin
if S = OpenChars[i] then
Editor.Canvas.TextOut(Pix.X, Pix.Y, CloseChars[i])
else Editor.Canvas.TextOut(Pix.X, Pix.Y, OpenChars[i]);
end;
end;
end; //if
end;//for i :=
Editor.Canvas.Brush.Style := bsSolid;
end;
end;
Logged In: YES
user_id=726063
Originator: YES
1. One post below is the ANSI PaintTransient fix.
2. The code below is a working version of PaintTransient for Unicode version
-----------------------------------------------------------------------------
procedure TChildForm.Memo1PaintTransient(Sender: TObject; Canvas: TCanvas;
TransientType: TTransientType);
var Editor : TSynEdit;
OpenChars: array of WideChar;//[0..2] of WideChar=();
CloseChars: array of WideChar;//[0..2] of WideChar=();
Attri: TSynHighlighterAttributes;
function IsCharBracket(AChar: WideChar): Boolean;
begin
case AChar of
'{','[','(','<','}',']',')','>':
Result := True;
else
Result := False;
end;
end;
function CharToPixels(P: TBufferCoord): TPoint;
begin
Result:=Editor.RowColumnToPixels(Editor.BufferToDisplayPos(P));
end;
procedure SetCanvasStyle;
begin
Editor.Canvas.Brush.Style := bsSolid;//Clear;
Editor.Canvas.Font.Assign(Editor.Font);
Editor.Canvas.Font.Style := Attri.Style;
if (TransientType = ttAfter) then
begin
Editor.Canvas.Font.Color := FBracketFG;
Editor.Canvas.Brush.Color := FBracketBG;
end else begin
Editor.Canvas.Font.Color := Attri.Foreground;
Editor.Canvas.Brush.Color := Attri.Background;
end;
if Editor.Canvas.Font.Color = clNone then
Editor.Canvas.Font.Color := Editor.Font.Color;
if Editor.Canvas.Brush.Color = clNone then
Editor.Canvas.Brush.Color := Editor.Color;
end;
var P: TBufferCoord;
Pix: TPoint;
D : TDisplayCoord;
S: WideString;
I: Integer;
ArrayLength: Integer;
start: Integer;
TmpCharA, TmpCharB: WideChar;
begin
try
// if Memo1.InReplaceStatus = False then
// begin
if fMain.SyntaxHEnabled = False then exit;
if Memo1.Highlighter = nil then exit;
if fMain.BracketMatching = False then exit;
if TSynEdit(Sender).SelAvail then exit;
Editor := TSynEdit(Sender);
ArrayLength:= 3;
if (Editor.Highlighter = SynHTMLSyn1) or (Editor.Highlighter = SynXMLSyn1) then
inc(ArrayLength);
SetLength(OpenChars, ArrayLength);
SetLength(CloseChars, ArrayLength);
for i := 0 to ArrayLength - 1 do
Case i of
0: begin OpenChars[i] := '('; CloseChars[i] := ')'; end;
1: begin OpenChars[i] := '{'; CloseChars[i] := '}'; end;
2: begin OpenChars[i] := '['; CloseChars[i] := ']'; end;
3: begin OpenChars[i] := '<'; CloseChars[i] := '>'; end;
end;
P := Editor.CaretXY;
D := Editor.DisplayXY;
Start := Editor.SelStart;
if (Start > 0) and (Start <= length(Editor.Text)) then
TmpCharA := Editor.Text[Start]
else
TmpCharA := #0;
if (Start < length(Editor.Text)) then
TmpCharB := Editor.Text[Start + 1]
else TmpCharB := #0;
if not IsCharBracket(TmpCharA) and not IsCharBracket(TmpCharB) then exit;
S := TmpCharB;
if not IsCharBracket(TmpCharB) then
begin
P.Char := P.Char - 1;
S := TmpCharA;
end;
Editor.GetHighlighterAttriAtRowCol(P, S, Attri);
if (Editor.Highlighter.SymbolAttribute = Attri) then
begin
for i := low(OpenChars) to High(OpenChars) do
begin
if (S = OpenChars[i]) or (S = CloseChars[i]) then
begin
Pix := CharToPixels(P);
SetCanvasStyle;
Editor.Canvas.TextOut(Pix.X, Pix.Y, S);
P := Editor.GetMatchingBracketEx(P);
if (P.Char > 0) and (P.Line > 0) then
begin
Pix := CharToPixels(P);
if Pix.X > Editor.Gutter.Width then
begin
SetCanvasStyle;
if S = OpenChars[i] then
Editor.Canvas.TextOut(Pix.X, Pix.Y, CloseChars[i])
else Editor.Canvas.TextOut(Pix.X, Pix.Y, OpenChars[i]);
end;
end;
end; //if
end;//for i :=
Editor.Canvas.Brush.Style := bsSolid;
end;
//end;
except
end;
end;
Logged In: YES
user_id=99702
Originator: NO
If I'm not missing something, the problem you're reporting is about the PaintTransient demo?
If so, I'm sorry but I don't think I will take the time to patch it...
If you want CVS access so you can fix it, just tell me.
Best regards,
Flávio
Logged In: YES
user_id=1312539
Originator: NO
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 30 days (the time period specified by
the administrator of this Tracker).