GetMatchingBracket as in Scintilla and other editors. #37
Closed
pyscripter
started this conversation in
Ideas
Replies: 1 comment
-
Hello
For many users it can be useful, so you can include it.
I am matching not only brackets, but pair keywords too, so I won't use it.
…--
Best regards
Jan Fiala
***@***.***
Hello,
sobota 5. listopadu 2022, 14:19:32, napsal jste:
TCustomSynEdit.GetMatchingBracket is used by ecMatchBracket. In PyScripter I have the following code:
function GetMatchingBracket(SynEdit : TSynEdit) : TBufferCoord;
function PosHasBracket(Pos: TBufferCoord; const Brackets: string; var BracketChar: Char): Boolean;
var
Token: string;
Attri: TSynHighlighterAttributes;
begin
if SynEdit.Highlighter <> nil then
begin
Result := SynEdit.GetHighlighterAttriAtRowCol(Pos, Token, Attri) and
(Attri = SynEdit.Highlighter.SymbolAttribute) and (Token.Length = 1) and
(Brackets.IndexOf(Token[1]) >= 0);
BracketChar := Token[1];
end
else
begin
var Line := SynEdit.Lines[Pos.Line - 1];
BracketChar := Line[Pos.Char];
Result := Brackets.IndexOf(BracketChar) >= 0;
end;
end;
var
Brackets: string;
BracketPos: TBufferCoord;
BracketChar: Char;
HaveBracket: Boolean;
begin
Result := BufferCoord(0, 0);
if Assigned(SynEdit.Highlighter) then
Brackets := SynEdit.Highlighter.Brackets
else
Brackets := '()[]{}<>';
BracketPos := SynEdit.CaretXY;
// First Look at the previous character like Site
if BracketPos.Char > 1 then Dec(BracketPos.Char);
HaveBracket := PosHasBracket(BracketPos, Brackets, BracketChar);
// If it is not a bracket then look at the next character;
if not HaveBracket and (SynEdit.CaretX > 1) then begin
Inc(BracketPos.Char);
HaveBracket := PosHasBracket(BracketPos, Brackets, BracketChar);
end;
if HaveBracket then
begin
Result := SynEdit.GetMatchingBracketEx(BracketPos, Brackets);
if Result.Char > 0 then
begin
var IsOpenChar := not Odd(Brackets.IndexOf(BracketChar));
var IsOutside := IsOpenChar xor (BracketPos.Char < SynEdit.CaretX);
if IsOutside xor not IsOpenChar then
Inc(Result.Char);
end;
end;
end;
@MShark67 @JaFi-cz Do you think this should be part of SynEdit?
I also have a custom SynEdit command ecSelMatchBracket (you get the idea). Would that be useful in SynEdit?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TCustomSynEdit.GetMatchingBracket is used by ecMatchBracket. In PyScripter I have the following code:
@MShark67 @JaFi-cz Do you think this should be part of SynEdit?
I also have a custom SynEdit command ecSelMatchBracket (you get the idea). Would that be useful in SynEdit?
Beta Was this translation helpful? Give feedback.
All reactions