synedit: add bracket highlight style option

git-svn-id: trunk@17577 -
This commit is contained in:
paul 2008-11-25 08:10:55 +00:00
parent efe9d531c3
commit c248a2aa3e
2 changed files with 69 additions and 23 deletions

View File

@ -454,6 +454,7 @@ type
procedure FontChanged(Sender: TObject); {$IFDEF SYN_LAZARUS}override;{$ENDIF}
function GetBlockBegin: TPoint;
function GetBlockEnd: TPoint;
function GetBracketHighlightStyle: TSynEditBracketHighlightStyle;
function GetCanPaste: Boolean;
function GetCanRedo: Boolean;
function GetCanUndo: Boolean;
@ -470,6 +471,8 @@ type
function GetSelectedColor : TSynSelectedColor;
function GetBracketMatchColor : TSynSelectedColor;
function GetMouseLinkColor : TSynSelectedColor;
procedure SetBracketHighlightStyle(
const AValue: TSynEditBracketHighlightStyle);
procedure SetOnGutterClick(const AValue : TGutterClickEvent);
procedure SetRealLines(const AValue : TStrings);
procedure SetSelectedColor(const AValue : TSynSelectedColor);
@ -924,6 +927,8 @@ type
property MouseLinkColor: TSynSelectedColor read GetMouseLinkColor;
property LineNumberColor: TSynSelectedColor read GetLineNumberColor;
property LineHighlightColor: TSynSelectedColor read GetLineHighlightColor;
property BracketHighlightStyle: TSynEditBracketHighlightStyle
read GetBracketHighlightStyle write SetBracketHighlightStyle;
//property Color: TSynSelectedColor read GetSelectedColor;
{$ELSE}
property SelectedColor: TSynSelectedColor
@ -1063,6 +1068,7 @@ type
{$IFDEF SYN_LAZARUS}
property IncrementColor;
property HighlightAllColor;
property BracketHighlightStyle;
property BracketMatchColor;
property MouseLinkColor;
property LineNumberColor;
@ -1616,10 +1622,12 @@ begin
if sfCaretChanged in fStateFlags then
UpdateCaret
else
if not(sfPainting in fStateFlags) and assigned(fMarkupBracket) then
if not(sfPainting in fStateFlags) then
begin
fMarkupBracket.InvalidateBracketHighlight;
fMarkupSpecialLine.InvalidateLineHighlight;
if Assigned(fMarkupBracket) then
fMarkupBracket.InvalidateBracketHighlight;
if Assigned(fMarkupSpecialLine) then
fMarkupSpecialLine.InvalidateLineHighlight;
end;
if fStatusChanges <> [] then
DoOnStatusChange(fStatusChanges);
@ -1702,6 +1710,11 @@ begin
Result := fBlockEnd;
end;
function TCustomSynEdit.GetBracketHighlightStyle: TSynEditBracketHighlightStyle;
begin
Result := fMarkupBracket.HighlightStyle;
end;
function TCustomSynEdit.CaretXPix: Integer;
var
p: TPoint;
@ -1792,6 +1805,12 @@ begin
Result := fMarkupCtrlMouse.MarkupInfo;
end;
procedure TCustomSynEdit.SetBracketHighlightStyle(
const AValue: TSynEditBracketHighlightStyle);
begin
fMarkupBracket.HighlightStyle := AValue;
end;
procedure TCustomSynEdit.SetOnGutterClick(const AValue : TGutterClickEvent);
begin
fGutter.OnGutterClick := AValue;

View File

@ -29,6 +29,11 @@ uses
Classes, SysUtils, Graphics, SynEditMarkup, SynEditMiscClasses, Controls, LCLProc;
type
TSynEditBracketHighlightStyle = (
sbhsLeftOfCursor,
sbhsRightOfCursor,
sbhsBoth
);
{ TSynEditMarkupBracket }
TSynEditMarkupBracket = class(TSynEditMarkup)
@ -36,6 +41,8 @@ type
// Physical Position
FBracketHighlightPos: TPoint;
FBracketHighlightAntiPos: TPoint;
FHighlightStyle: TSynEditBracketHighlightStyle;
procedure SetHighlightStyle(const AValue: TSynEditBracketHighlightStyle);
protected
procedure FindMatchingBracketPair(PhysCaret: TPoint;
var StartBracket, EndBracket: TPoint);
@ -46,6 +53,7 @@ type
function GetNextMarkupColAfterRowCol(const aRow, aCol: Integer): Integer; override;
procedure InvalidateBracketHighlight;
property HighlightStyle: TSynEditBracketHighlightStyle read FHighlightStyle write SetHighlightStyle;
end;
implementation
@ -59,47 +67,66 @@ begin
inherited Create(ASynEdit);
FBracketHighlightPos.Y := -1;
FBracketHighlightAntiPos.Y := -1;
FHighlightStyle := sbhsBoth;
MarkupInfo.Foreground := clNone;
MarkupInfo.Background := clNone;
MarkupInfo.Style := [fsBold];
MarkupInfo.StyleMask := [];
end;
procedure TSynEditMarkupBracket.FindMatchingBracketPair(PhysCaret : TPoint;
var StartBracket, EndBracket : TPoint);
procedure TSynEditMarkupBracket.SetHighlightStyle(
const AValue: TSynEditBracketHighlightStyle);
begin
if FHighlightStyle <> AValue then
begin
FHighlightStyle := AValue;
InvalidateBracketHighlight;
end;
end;
procedure TSynEditMarkupBracket.FindMatchingBracketPair(PhysCaret: TPoint;
var StartBracket, EndBracket: TPoint);
const
Brackets: set of Char = ['(',')','{','}','[',']'];
var
StartLine: string;
LogCaretXY: TPoint;
x: Integer;
begin
StartBracket.Y:=-1;
EndBracket.Y:=-1;
if (PhysCaret.Y<1) or (PhysCaret.Y>Lines.Count) or (PhysCaret.X<1) then exit;
StartBracket.Y := -1;
EndBracket.Y := -1;
if (PhysCaret.Y < 1) or (PhysCaret.Y > Lines.Count) or (PhysCaret.X < 1) then
Exit;
StartLine := Lines[PhysCaret.Y - 1];
// check for bracket, before cursor
if PhysCaret.x > 1 then begin
// check for bracket, left of cursor
if (HighlightStyle in [sbhsLeftOfCursor, sbhsBoth]) and (PhysCaret.x > 1) then
begin
// need to dec PhysCaret, in case we are in the middle of a tab
dec(PhysCaret.x);
LogCaretXY:=TSynEdit(SynEdit).PhysicalToLogicalPos(PhysCaret);
LogCaretXY := TSynEdit(SynEdit).PhysicalToLogicalPos(PhysCaret);
x := LogCaretXY.x;
if (x <= length(StartLine))
and (StartLine[x] in ['(',')','{','}','[',']']) then begin
StartBracket:=PhysCaret;
EndBracket:=TSynEdit(SynEdit).FindMatchingBracket(PhysCaret,false,false,false,false);
exit;
if (x <= length(StartLine)) and (StartLine[x] in Brackets) then
begin
StartBracket := PhysCaret;
EndBracket := TSynEdit(SynEdit).FindMatchingBracket(PhysCaret, False, False, False, False);
Exit;
end;
// check for bracket after caret
inc(PhysCaret.x);;
end;
LogCaretXY:=TSynEdit(SynEdit).PhysicalToLogicalPos(PhysCaret);
x := LogCaretXY.x;
if (length(StartLine) < x)
or (not (StartLine[x] in ['(',')','{','}','[',']'])) then exit;
StartBracket:=PhysCaret;
EndBracket:=TSynEdit(SynEdit).FindMatchingBracket(PhysCaret,false,false,false,false);
if (HighlightStyle in [sbhsRightOfCursor, sbhsBoth]) then
begin
LogCaretXY := TSynEdit(SynEdit).PhysicalToLogicalPos(PhysCaret);
x := LogCaretXY.x;
if (x <= length(StartLine)) and (StartLine[x] in Brackets) then
begin
StartBracket := PhysCaret;
EndBracket := TSynEdit(SynEdit).FindMatchingBracket(PhysCaret, False, False, False, False);
end;
end;
end;
procedure TSynEditMarkupBracket.InvalidateBracketHighlight;