editor, use TSynEdit markup to highligh current identifier matches

This commit is contained in:
Basile Burg 2015-12-11 08:39:02 +01:00
parent 95b11b821d
commit 87f8385f50
4 changed files with 32 additions and 48 deletions

View File

@ -61,7 +61,7 @@ type
function find(const aValue: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function find(const aValue: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
end; end;
TTokenKind = (tkCommt, tkIdent, tkKeywd, tkStrng, tkBlank, tkSymbl, tkNumbr, tkCurrI, tkDDocs, tkSpecK); TTokenKind = (tkCommt, tkIdent, tkKeywd, tkStrng, tkBlank, tkSymbl, tkNumbr, tkDDocs, tkSpecK);
TRangeKind = (rkString1, rkString2, rkTokString, rkBlockCom1, rkBlockCom2, rkBlockDoc1, rkBlockDoc2, rkAsm); TRangeKind = (rkString1, rkString2, rkTokString, rkBlockCom1, rkBlockCom2, rkBlockDoc1, rkBlockDoc2, rkAsm);
@ -114,7 +114,6 @@ type
fSpeckAttrib: TSynHighlighterAttributes; fSpeckAttrib: TSynHighlighterAttributes;
fKeyWords: TD2Dictionary; fKeyWords: TD2Dictionary;
fSpecKw: TD2Dictionary; fSpecKw: TD2Dictionary;
fCurrIdent: string;
fLineBuf: string; fLineBuf: string;
fTokStart, fTokStop: Integer; fTokStart, fTokStop: Integer;
fTokKind: TTokenKind; fTokKind: TTokenKind;
@ -134,7 +133,6 @@ type
procedure setAsblrAttrib(value: TSynHighlighterAttributes); procedure setAsblrAttrib(value: TSynHighlighterAttributes);
procedure setSpeckAttrib(value: TSynHighlighterAttributes); procedure setSpeckAttrib(value: TSynHighlighterAttributes);
procedure doAttribChange(sender: TObject); procedure doAttribChange(sender: TObject);
procedure setCurrIdent(const value: string);
procedure doChanged; procedure doChanged;
protected protected
function GetRangeClass: TSynCustomHighlighterRangeClass; override; function GetRangeClass: TSynCustomHighlighterRangeClass; override;
@ -147,7 +145,7 @@ type
property CommtAttrib: TSynHighlighterAttributes read fCommtAttrib write setCommtAttrib; property CommtAttrib: TSynHighlighterAttributes read fCommtAttrib write setCommtAttrib;
property StrngAttrib: TSynHighlighterAttributes read fStrngAttrib write setStrngAttrib; property StrngAttrib: TSynHighlighterAttributes read fStrngAttrib write setStrngAttrib;
property KeywdAttrib: TSynHighlighterAttributes read fKeywdAttrib write setKeywdAttrib; property KeywdAttrib: TSynHighlighterAttributes read fKeywdAttrib write setKeywdAttrib;
property CurrIAttrib: TSynHighlighterAttributes read fCurrIAttrib write setCurrIAttrib; property CurrIAttrib: TSynHighlighterAttributes read fCurrIAttrib write setCurrIAttrib stored false;
property DDocsAttrib: TSynHighlighterAttributes read fDDocsAttrib write setDDocsAttrib; property DDocsAttrib: TSynHighlighterAttributes read fDDocsAttrib write setDDocsAttrib;
property AsblrAttrib: TSynHighlighterAttributes read fAsblrAttrib write setAsblrAttrib; property AsblrAttrib: TSynHighlighterAttributes read fAsblrAttrib write setAsblrAttrib;
property SpeckAttrib: TSynHighlighterAttributes read fSpeckAttrib write setSpeckAttrib; property SpeckAttrib: TSynHighlighterAttributes read fSpeckAttrib write setSpeckAttrib;
@ -167,7 +165,6 @@ type
procedure SetRange(Value: Pointer); override; procedure SetRange(Value: Pointer); override;
procedure ResetRange; override; procedure ResetRange; override;
function GetRange: Pointer; override; function GetRange: Pointer; override;
property CurrentIdentifier: string read fCurrIdent write setCurrIdent;
end; end;
implementation implementation
@ -350,7 +347,6 @@ begin
fAttribLut[TTokenKind.tkNumbr] := fNumbrAttrib; fAttribLut[TTokenKind.tkNumbr] := fNumbrAttrib;
fAttribLut[TTokenKind.tkStrng] := fStrngAttrib; fAttribLut[TTokenKind.tkStrng] := fStrngAttrib;
fAttribLut[TTokenKind.tksymbl] := fSymblAttrib; fAttribLut[TTokenKind.tksymbl] := fSymblAttrib;
fAttribLut[TTokenKind.tkCurrI] := fCurrIAttrib;
fAttribLut[TTokenKind.tkDDocs] := fDDocsAttrib; fAttribLut[TTokenKind.tkDDocs] := fDDocsAttrib;
fAttribLut[TTokenKind.tkSpecK] := fSpeckAttrib; fAttribLut[TTokenKind.tkSpecK] := fSpeckAttrib;
@ -458,13 +454,6 @@ begin
fSpeckAttrib.Assign(value); fSpeckAttrib.Assign(value);
end; end;
procedure TSynD2Syn.setCurrIdent(const value: string);
begin
if fCurrIdent = value then Exit;
fCurrIdent := value;
doChanged;
end;
procedure TSynD2Syn.setLine(const NewValue: String; LineNumber: Integer); procedure TSynD2Syn.setLine(const NewValue: String; LineNumber: Integer);
begin begin
inherited; inherited;
@ -855,9 +844,7 @@ begin
if fKeyWords.find(fLineBuf[FTokStart..fTokStop-1]) then if fKeyWords.find(fLineBuf[FTokStart..fTokStop-1]) then
fTokKind := tkKeywd fTokKind := tkKeywd
else if fSpecKw.find(fLineBuf[FTokStart..fTokStop-1]) then else if fSpecKw.find(fLineBuf[FTokStart..fTokStop-1]) then
fTokKind := tkSpecK fTokKind := tkSpecK;
else if fLineBuf[FTokStart..fTokStop-1] = fCurrIdent then
fTokKind := tkCurrI;
//check asm range //check asm range
if fTokKind = tkKeywd then if fTokKind = tkKeywd then
if fLineBuf[FTokStart..fTokStop-1] = 'asm' then if fLineBuf[FTokStart..fTokStop-1] = 'asm' then

View File

@ -35,6 +35,7 @@ type
fFoldedColor: TSynSelectedColor; fFoldedColor: TSynSelectedColor;
fMouseLinkColor: TSynSelectedColor; fMouseLinkColor: TSynSelectedColor;
fBracketMatchColor: TSynSelectedColor; fBracketMatchColor: TSynSelectedColor;
fIdentifierMarkup: TSynSelectedColor;
fFont: TFont; fFont: TFont;
// //
fDDocDelay: Integer; fDDocDelay: Integer;
@ -59,6 +60,7 @@ type
procedure setFoldedColor(value: TSynSelectedColor); procedure setFoldedColor(value: TSynSelectedColor);
procedure setMouseLinkColor(value: TSynSelectedColor); procedure setMouseLinkColor(value: TSynSelectedColor);
procedure setBracketMatchColor(value: TSynSelectedColor); procedure setBracketMatchColor(value: TSynSelectedColor);
procedure SetIdentifierMarkup(value: TSynSelectedColor);
procedure setD2Syn(value: TPersistent); procedure setD2Syn(value: TPersistent);
procedure setTxtSyn(value: TPersistent); procedure setTxtSyn(value: TPersistent);
procedure setShortcuts(value: TCollection); procedure setShortcuts(value: TCollection);
@ -77,6 +79,7 @@ type
property mouseLinkColor: TSynSelectedColor read fMouseLinkColor write setMouseLinkColor; property mouseLinkColor: TSynSelectedColor read fMouseLinkColor write setMouseLinkColor;
property selectedColor: TSynSelectedColor read fSelCol write setSelCol; property selectedColor: TSynSelectedColor read fSelCol write setSelCol;
property foldedColor: TSynSelectedColor read fFoldedColor write setFoldedColor; property foldedColor: TSynSelectedColor read fFoldedColor write setFoldedColor;
property identifierColor: TSynSelectedColor read fIdentifierMarkup write SetIdentifierMarkup;
property background: TColor read fBackground write fBackground default clWhite; property background: TColor read fBackground write fBackground default clWhite;
property tabulationWidth: Integer read fTabWidth write fTabWidth default 4; property tabulationWidth: Integer read fTabWidth write fTabWidth default 4;
property blockIdentation: Integer read fBlockIdent write fBlockIdent default 4; property blockIdentation: Integer read fBlockIdent write fBlockIdent default 4;
@ -165,6 +168,7 @@ begin
fFoldedColor := TSynSelectedColor.Create; fFoldedColor := TSynSelectedColor.Create;
fMouseLinkColor := TSynSelectedColor.Create; fMouseLinkColor := TSynSelectedColor.Create;
fBracketMatchColor := TSynSelectedColor.Create; fBracketMatchColor := TSynSelectedColor.Create;
fIdentifierMarkup := TSynSelectedColor.Create;
// //
// note: default values come from TSynEditFoldedView ctor. // note: default values come from TSynEditFoldedView ctor.
fFoldedColor.Background := clNone; fFoldedColor.Background := clNone;
@ -179,6 +183,9 @@ begin
fBracketMatchColor.Foreground := clRed; fBracketMatchColor.Foreground := clRed;
fBracketMatchColor.Background := clNone; fBracketMatchColor.Background := clNone;
// //
fIdentifierMarkup.Foreground:= clNone;
fIdentifierMarkup.Background:= clSilver;
//
fCompletionMenuHeight:= 260; fCompletionMenuHeight:= 260;
fCompletionMenuWidth:= 160; fCompletionMenuWidth:= 160;
fCompletionMenuLines:= 15; fCompletionMenuLines:= 15;
@ -222,6 +229,7 @@ begin
fFoldedColor.Free; fFoldedColor.Free;
fMouseLinkColor.Free; fMouseLinkColor.Free;
fBracketMatchColor.Free; fBracketMatchColor.Free;
fIdentifierMarkup.Free;
inherited; inherited;
end; end;
@ -313,6 +321,11 @@ begin
fBracketMatchColor.Assign(value); fBracketMatchColor.Assign(value);
end; end;
procedure TCEEditorOptionsBase.SetIdentifierMarkup(value: TSynSelectedColor);
begin
fIdentifierMarkup.Assign(value);
end;
procedure TCEEditorOptionsBase.setD2Syn(value: TPersistent); procedure TCEEditorOptionsBase.setD2Syn(value: TPersistent);
begin begin
D2Syn.Assign(value); D2Syn.Assign(value);
@ -560,6 +573,7 @@ begin
anEditor.FoldedCodeColor.Assign(fFoldedColor); anEditor.FoldedCodeColor.Assign(fFoldedColor);
anEditor.MouseLinkColor.Assign(fMouseLinkColor); anEditor.MouseLinkColor.Assign(fMouseLinkColor);
anEditor.BracketMatchColor.Assign(fBracketMatchColor); anEditor.BracketMatchColor.Assign(fBracketMatchColor);
anEditor.HighlightAllColor.Assign(fIdentifierMarkup);
anEditor.TabWidth := tabulationWidth; anEditor.TabWidth := tabulationWidth;
anEditor.BlockIndent := blockIdentation; anEditor.BlockIndent := blockIdentation;
anEditor.ExtraLineSpacing := lineSpacing; anEditor.ExtraLineSpacing := lineSpacing;

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc, Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc,
SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText, SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText,
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView, SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
SynEditMarks, SynEditMarks, SynEditMarkup, SynEditTypes,
ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs, ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs,
ce_sharedres; ce_sharedres;
@ -120,7 +120,7 @@ type
fBreakpointEvent: TBreakPointModifyEvent; fBreakpointEvent: TBreakPointModifyEvent;
function getMouseFileBytePos: Integer; function getMouseFileBytePos: Integer;
procedure changeNotify(Sender: TObject); procedure changeNotify(Sender: TObject);
procedure identifierToD2Syn; procedure highlightCurrentIdentifier;
procedure saveCache; procedure saveCache;
procedure loadCache; procedure loadCache;
class procedure cleanCache; static; class procedure cleanCache; static;
@ -427,6 +427,9 @@ end;
{$REGION Standard Obj and Comp -------------------------------------------------} {$REGION Standard Obj and Comp -------------------------------------------------}
constructor TCESynMemo.Create(aOwner: TComponent); constructor TCESynMemo.Create(aOwner: TComponent);
var
i: integer;
mgr: TSynEditMarkupManager;
begin begin
inherited; inherited;
// //
@ -496,6 +499,9 @@ begin
fPositions := TCESynMemoPositions.create(self); fPositions := TCESynMemoPositions.create(self);
fMultiDocSubject := TCEMultiDocSubject.create; fMultiDocSubject := TCEMultiDocSubject.create;
// //
HighlightAllColor.Foreground:= clNone;
HighlightAllColor.Background:= clSilver;
//
subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self); subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self);
end; end;
@ -531,7 +537,7 @@ begin
inherited; inherited;
checkFileDate; checkFileDate;
// //
identifierToD2Syn; highlightCurrentIdentifier;
subjDocFocused(TCEMultiDocSubject(fMultiDocSubject), self); subjDocFocused(TCEMultiDocSubject(fMultiDocSubject), self);
end; end;
@ -834,18 +840,15 @@ begin
fIsTxtFile := Highlighter = fTxtHighlighter; fIsTxtFile := Highlighter = fTxtHighlighter;
end; end;
procedure TCESynMemo.identifierToD2Syn; procedure TCESynMemo.highlightCurrentIdentifier;
begin begin
fIdentifier := GetWordAtRowCol(LogicalCaretXY); fIdentifier := GetWordAtRowCol(LogicalCaretXY);
if Highlighter = fD2Highlighter then SetHighlightSearch(fIdentifier,[ssoEntireScope]);
fD2Highlighter.CurrentIdentifier := fIdentifier
else if Highlighter = fTxtHighlighter then
fTxtHighlighter.CurrIdent := fIdentifier;
end; end;
procedure TCESynMemo.changeNotify(Sender: TObject); procedure TCESynMemo.changeNotify(Sender: TObject);
begin begin
identifierToD2Syn; highlightCurrentIdentifier;
fModified := true; fModified := true;
fPositions.store; fPositions.store;
subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self); subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
@ -1010,7 +1013,7 @@ end;
procedure TCESynMemo.KeyDown(var Key: Word; Shift: TShiftState); procedure TCESynMemo.KeyDown(var Key: Word; Shift: TShiftState);
begin begin
inherited; inherited;
identifierToD2Syn; highlightCurrentIdentifier;
case Key of case Key of
VK_BROWSER_BACK: fPositions.back; VK_BROWSER_BACK: fPositions.back;
VK_BROWSER_FORWARD: fPositions.next; VK_BROWSER_FORWARD: fPositions.next;
@ -1078,13 +1081,13 @@ begin
fOldMousePos := Point(X, Y); fOldMousePos := Point(X, Y);
fMousePos := PixelsToRowColumn(fOldMousePos); fMousePos := PixelsToRowColumn(fOldMousePos);
if ssLeft in Shift then if ssLeft in Shift then
identifierToD2Syn; highlightCurrentIdentifier;
end; end;
procedure TCESynMemo.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:Integer); procedure TCESynMemo.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:Integer);
begin begin
inherited; inherited;
identifierToD2Syn; highlightCurrentIdentifier;
fCanShowHint := false; fCanShowHint := false;
fDDocWin.Hide; fDDocWin.Hide;
fCallTipWin.Hide; fCallTipWin.Hide;

View File

@ -24,7 +24,6 @@ type
procedure setSymAttribs(aValue: TSynHighlighterAttributes); procedure setSymAttribs(aValue: TSynHighlighterAttributes);
procedure setTxtAttribs(aValue: TSynHighlighterAttributes); procedure setTxtAttribs(aValue: TSynHighlighterAttributes);
procedure setWhiAttribs(aValue: TSynHighlighterAttributes); procedure setWhiAttribs(aValue: TSynHighlighterAttributes);
procedure setCurrIdent(const aValue: string);
published published
property symbAttributes: TSynHighlighterAttributes read fSymAttribs write setSymAttribs; property symbAttributes: TSynHighlighterAttributes read fSymAttribs write setSymAttribs;
property textAttributes: TSynHighlighterAttributes read fTxtAttribs write setTxtAttribs; property textAttributes: TSynHighlighterAttributes read fTxtAttribs write setTxtAttribs;
@ -41,8 +40,6 @@ type
function GetTokenKind: integer; override; function GetTokenKind: integer; override;
function GetTokenPos: Integer; override; function GetTokenPos: Integer; override;
function GetEol: Boolean; override; function GetEol: Boolean; override;
//
property CurrIdent: string read fCurrIdent write setCurrIdent;
end; end;
const const
@ -98,16 +95,6 @@ begin
fWhiAttribs.Assign(aValue); fWhiAttribs.Assign(aValue);
end; end;
procedure TSynTxtSyn.setCurrIdent(const aValue: string);
begin
if fCurrIdent = aValue then
Exit;
fCurrIdent := aValue;
BeginUpdate;
fUpdateChange := True;
EndUpdate;
end;
procedure TSynTxtSyn.setLine(const NewValue: String; LineNumber: Integer); procedure TSynTxtSyn.setLine(const NewValue: String; LineNumber: Integer);
begin begin
inherited; inherited;
@ -173,13 +160,6 @@ function TSynTxtSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin begin
Result := fTokToAttri[fToken]; Result := fTokToAttri[fToken];
Result.FrameEdges := sfeNone; Result.FrameEdges := sfeNone;
if fCurrIdent <> '' then
if GetToken = fCurrIdent then
begin
Result.FrameColor := Result.Foreground;
Result.FrameStyle := slsSolid;
Result.FrameEdges := sfeAround;
end;
end; end;
function TSynTxtSyn.GetTokenPos: Integer; function TSynTxtSyn.GetTokenPos: Integer;