mirror of https://gitlab.com/basile.b/dexed.git
editor, use TSynEdit markup to highligh current identifier matches
This commit is contained in:
parent
95b11b821d
commit
87f8385f50
|
|
@ -61,7 +61,7 @@ type
|
|||
function find(const aValue: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
|
||||
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);
|
||||
|
||||
|
|
@ -114,7 +114,6 @@ type
|
|||
fSpeckAttrib: TSynHighlighterAttributes;
|
||||
fKeyWords: TD2Dictionary;
|
||||
fSpecKw: TD2Dictionary;
|
||||
fCurrIdent: string;
|
||||
fLineBuf: string;
|
||||
fTokStart, fTokStop: Integer;
|
||||
fTokKind: TTokenKind;
|
||||
|
|
@ -134,7 +133,6 @@ type
|
|||
procedure setAsblrAttrib(value: TSynHighlighterAttributes);
|
||||
procedure setSpeckAttrib(value: TSynHighlighterAttributes);
|
||||
procedure doAttribChange(sender: TObject);
|
||||
procedure setCurrIdent(const value: string);
|
||||
procedure doChanged;
|
||||
protected
|
||||
function GetRangeClass: TSynCustomHighlighterRangeClass; override;
|
||||
|
|
@ -147,7 +145,7 @@ type
|
|||
property CommtAttrib: TSynHighlighterAttributes read fCommtAttrib write setCommtAttrib;
|
||||
property StrngAttrib: TSynHighlighterAttributes read fStrngAttrib write setStrngAttrib;
|
||||
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 AsblrAttrib: TSynHighlighterAttributes read fAsblrAttrib write setAsblrAttrib;
|
||||
property SpeckAttrib: TSynHighlighterAttributes read fSpeckAttrib write setSpeckAttrib;
|
||||
|
|
@ -167,7 +165,6 @@ type
|
|||
procedure SetRange(Value: Pointer); override;
|
||||
procedure ResetRange; override;
|
||||
function GetRange: Pointer; override;
|
||||
property CurrentIdentifier: string read fCurrIdent write setCurrIdent;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
|
@ -350,7 +347,6 @@ begin
|
|||
fAttribLut[TTokenKind.tkNumbr] := fNumbrAttrib;
|
||||
fAttribLut[TTokenKind.tkStrng] := fStrngAttrib;
|
||||
fAttribLut[TTokenKind.tksymbl] := fSymblAttrib;
|
||||
fAttribLut[TTokenKind.tkCurrI] := fCurrIAttrib;
|
||||
fAttribLut[TTokenKind.tkDDocs] := fDDocsAttrib;
|
||||
fAttribLut[TTokenKind.tkSpecK] := fSpeckAttrib;
|
||||
|
||||
|
|
@ -458,13 +454,6 @@ begin
|
|||
fSpeckAttrib.Assign(value);
|
||||
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);
|
||||
begin
|
||||
inherited;
|
||||
|
|
@ -855,9 +844,7 @@ begin
|
|||
if fKeyWords.find(fLineBuf[FTokStart..fTokStop-1]) then
|
||||
fTokKind := tkKeywd
|
||||
else if fSpecKw.find(fLineBuf[FTokStart..fTokStop-1]) then
|
||||
fTokKind := tkSpecK
|
||||
else if fLineBuf[FTokStart..fTokStop-1] = fCurrIdent then
|
||||
fTokKind := tkCurrI;
|
||||
fTokKind := tkSpecK;
|
||||
//check asm range
|
||||
if fTokKind = tkKeywd then
|
||||
if fLineBuf[FTokStart..fTokStop-1] = 'asm' then
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type
|
|||
fFoldedColor: TSynSelectedColor;
|
||||
fMouseLinkColor: TSynSelectedColor;
|
||||
fBracketMatchColor: TSynSelectedColor;
|
||||
fIdentifierMarkup: TSynSelectedColor;
|
||||
fFont: TFont;
|
||||
//
|
||||
fDDocDelay: Integer;
|
||||
|
|
@ -59,6 +60,7 @@ type
|
|||
procedure setFoldedColor(value: TSynSelectedColor);
|
||||
procedure setMouseLinkColor(value: TSynSelectedColor);
|
||||
procedure setBracketMatchColor(value: TSynSelectedColor);
|
||||
procedure SetIdentifierMarkup(value: TSynSelectedColor);
|
||||
procedure setD2Syn(value: TPersistent);
|
||||
procedure setTxtSyn(value: TPersistent);
|
||||
procedure setShortcuts(value: TCollection);
|
||||
|
|
@ -77,6 +79,7 @@ type
|
|||
property mouseLinkColor: TSynSelectedColor read fMouseLinkColor write setMouseLinkColor;
|
||||
property selectedColor: TSynSelectedColor read fSelCol write setSelCol;
|
||||
property foldedColor: TSynSelectedColor read fFoldedColor write setFoldedColor;
|
||||
property identifierColor: TSynSelectedColor read fIdentifierMarkup write SetIdentifierMarkup;
|
||||
property background: TColor read fBackground write fBackground default clWhite;
|
||||
property tabulationWidth: Integer read fTabWidth write fTabWidth default 4;
|
||||
property blockIdentation: Integer read fBlockIdent write fBlockIdent default 4;
|
||||
|
|
@ -165,6 +168,7 @@ begin
|
|||
fFoldedColor := TSynSelectedColor.Create;
|
||||
fMouseLinkColor := TSynSelectedColor.Create;
|
||||
fBracketMatchColor := TSynSelectedColor.Create;
|
||||
fIdentifierMarkup := TSynSelectedColor.Create;
|
||||
//
|
||||
// note: default values come from TSynEditFoldedView ctor.
|
||||
fFoldedColor.Background := clNone;
|
||||
|
|
@ -179,6 +183,9 @@ begin
|
|||
fBracketMatchColor.Foreground := clRed;
|
||||
fBracketMatchColor.Background := clNone;
|
||||
//
|
||||
fIdentifierMarkup.Foreground:= clNone;
|
||||
fIdentifierMarkup.Background:= clSilver;
|
||||
//
|
||||
fCompletionMenuHeight:= 260;
|
||||
fCompletionMenuWidth:= 160;
|
||||
fCompletionMenuLines:= 15;
|
||||
|
|
@ -222,6 +229,7 @@ begin
|
|||
fFoldedColor.Free;
|
||||
fMouseLinkColor.Free;
|
||||
fBracketMatchColor.Free;
|
||||
fIdentifierMarkup.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
|
@ -313,6 +321,11 @@ begin
|
|||
fBracketMatchColor.Assign(value);
|
||||
end;
|
||||
|
||||
procedure TCEEditorOptionsBase.SetIdentifierMarkup(value: TSynSelectedColor);
|
||||
begin
|
||||
fIdentifierMarkup.Assign(value);
|
||||
end;
|
||||
|
||||
procedure TCEEditorOptionsBase.setD2Syn(value: TPersistent);
|
||||
begin
|
||||
D2Syn.Assign(value);
|
||||
|
|
@ -560,6 +573,7 @@ begin
|
|||
anEditor.FoldedCodeColor.Assign(fFoldedColor);
|
||||
anEditor.MouseLinkColor.Assign(fMouseLinkColor);
|
||||
anEditor.BracketMatchColor.Assign(fBracketMatchColor);
|
||||
anEditor.HighlightAllColor.Assign(fIdentifierMarkup);
|
||||
anEditor.TabWidth := tabulationWidth;
|
||||
anEditor.BlockIndent := blockIdentation;
|
||||
anEditor.ExtraLineSpacing := lineSpacing;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ uses
|
|||
Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc,
|
||||
SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText,
|
||||
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
|
||||
SynEditMarks,
|
||||
SynEditMarks, SynEditMarkup, SynEditTypes,
|
||||
ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs,
|
||||
ce_sharedres;
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ type
|
|||
fBreakpointEvent: TBreakPointModifyEvent;
|
||||
function getMouseFileBytePos: Integer;
|
||||
procedure changeNotify(Sender: TObject);
|
||||
procedure identifierToD2Syn;
|
||||
procedure highlightCurrentIdentifier;
|
||||
procedure saveCache;
|
||||
procedure loadCache;
|
||||
class procedure cleanCache; static;
|
||||
|
|
@ -427,6 +427,9 @@ end;
|
|||
|
||||
{$REGION Standard Obj and Comp -------------------------------------------------}
|
||||
constructor TCESynMemo.Create(aOwner: TComponent);
|
||||
var
|
||||
i: integer;
|
||||
mgr: TSynEditMarkupManager;
|
||||
begin
|
||||
inherited;
|
||||
//
|
||||
|
|
@ -496,6 +499,9 @@ begin
|
|||
fPositions := TCESynMemoPositions.create(self);
|
||||
fMultiDocSubject := TCEMultiDocSubject.create;
|
||||
//
|
||||
HighlightAllColor.Foreground:= clNone;
|
||||
HighlightAllColor.Background:= clSilver;
|
||||
//
|
||||
subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self);
|
||||
end;
|
||||
|
||||
|
|
@ -531,7 +537,7 @@ begin
|
|||
inherited;
|
||||
checkFileDate;
|
||||
//
|
||||
identifierToD2Syn;
|
||||
highlightCurrentIdentifier;
|
||||
subjDocFocused(TCEMultiDocSubject(fMultiDocSubject), self);
|
||||
end;
|
||||
|
||||
|
|
@ -834,18 +840,15 @@ begin
|
|||
fIsTxtFile := Highlighter = fTxtHighlighter;
|
||||
end;
|
||||
|
||||
procedure TCESynMemo.identifierToD2Syn;
|
||||
procedure TCESynMemo.highlightCurrentIdentifier;
|
||||
begin
|
||||
fIdentifier := GetWordAtRowCol(LogicalCaretXY);
|
||||
if Highlighter = fD2Highlighter then
|
||||
fD2Highlighter.CurrentIdentifier := fIdentifier
|
||||
else if Highlighter = fTxtHighlighter then
|
||||
fTxtHighlighter.CurrIdent := fIdentifier;
|
||||
SetHighlightSearch(fIdentifier,[ssoEntireScope]);
|
||||
end;
|
||||
|
||||
procedure TCESynMemo.changeNotify(Sender: TObject);
|
||||
begin
|
||||
identifierToD2Syn;
|
||||
highlightCurrentIdentifier;
|
||||
fModified := true;
|
||||
fPositions.store;
|
||||
subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
|
||||
|
|
@ -1010,7 +1013,7 @@ end;
|
|||
procedure TCESynMemo.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
inherited;
|
||||
identifierToD2Syn;
|
||||
highlightCurrentIdentifier;
|
||||
case Key of
|
||||
VK_BROWSER_BACK: fPositions.back;
|
||||
VK_BROWSER_FORWARD: fPositions.next;
|
||||
|
|
@ -1078,13 +1081,13 @@ begin
|
|||
fOldMousePos := Point(X, Y);
|
||||
fMousePos := PixelsToRowColumn(fOldMousePos);
|
||||
if ssLeft in Shift then
|
||||
identifierToD2Syn;
|
||||
highlightCurrentIdentifier;
|
||||
end;
|
||||
|
||||
procedure TCESynMemo.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:Integer);
|
||||
begin
|
||||
inherited;
|
||||
identifierToD2Syn;
|
||||
highlightCurrentIdentifier;
|
||||
fCanShowHint := false;
|
||||
fDDocWin.Hide;
|
||||
fCallTipWin.Hide;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ type
|
|||
procedure setSymAttribs(aValue: TSynHighlighterAttributes);
|
||||
procedure setTxtAttribs(aValue: TSynHighlighterAttributes);
|
||||
procedure setWhiAttribs(aValue: TSynHighlighterAttributes);
|
||||
procedure setCurrIdent(const aValue: string);
|
||||
published
|
||||
property symbAttributes: TSynHighlighterAttributes read fSymAttribs write setSymAttribs;
|
||||
property textAttributes: TSynHighlighterAttributes read fTxtAttribs write setTxtAttribs;
|
||||
|
|
@ -41,8 +40,6 @@ type
|
|||
function GetTokenKind: integer; override;
|
||||
function GetTokenPos: Integer; override;
|
||||
function GetEol: Boolean; override;
|
||||
//
|
||||
property CurrIdent: string read fCurrIdent write setCurrIdent;
|
||||
end;
|
||||
|
||||
const
|
||||
|
|
@ -98,16 +95,6 @@ begin
|
|||
fWhiAttribs.Assign(aValue);
|
||||
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);
|
||||
begin
|
||||
inherited;
|
||||
|
|
@ -173,13 +160,6 @@ function TSynTxtSyn.GetTokenAttribute: TSynHighlighterAttributes;
|
|||
begin
|
||||
Result := fTokToAttri[fToken];
|
||||
Result.FrameEdges := sfeNone;
|
||||
if fCurrIdent <> '' then
|
||||
if GetToken = fCurrIdent then
|
||||
begin
|
||||
Result.FrameColor := Result.Foreground;
|
||||
Result.FrameStyle := slsSolid;
|
||||
Result.FrameEdges := sfeAround;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynTxtSyn.GetTokenPos: Integer;
|
||||
|
|
|
|||
Loading…
Reference in New Issue