mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 14:29:33 +02:00
SynEdit: Refactor TSynSelectedColorMergeResult - fix inheritance structure.
- This change affects compatibility for Highlighters: Code requiring the a tokens Attribute must now decide if it should call "GetTokenAttribute" / "GetEndOfLineAttribute" or "GetTokenAttributeEx" / "GetEndOfLineAttributeEx"
This commit is contained in:
parent
5abe12a280
commit
6690e16115
@ -25,6 +25,7 @@ uses
|
|||||||
Classes, SysUtils, Graphics;
|
Classes, SysUtils, Graphics;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
// TODO: TLazEditDisplayTokenBound is not yet supporting wrapped text - The Physical value may change
|
||||||
TLazEditDisplayTokenBound = record
|
TLazEditDisplayTokenBound = record
|
||||||
Physical: Integer; // 1 based - May be in middle of char
|
Physical: Integer; // 1 based - May be in middle of char
|
||||||
Logical: Integer; // 1 based
|
Logical: Integer; // 1 based
|
||||||
|
@ -34,7 +34,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Graphics, LCLProc, SynEditTypes, SynEditMiscProcs,
|
Classes, SysUtils, Graphics, LCLProc, SynEditTypes, SynEditMiscProcs,
|
||||||
SynEditHighlighter, SynEditKeyCmds, SynEditTextBase;
|
SynEditHighlighter, SynEditKeyCmds, SynEditTextBase, LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
TSynEditStrings = class;
|
TSynEditStrings = class;
|
||||||
@ -208,7 +208,7 @@ type
|
|||||||
TLazSynDisplayTokenInfo = record
|
TLazSynDisplayTokenInfo = record
|
||||||
TokenStart: PChar;
|
TokenStart: PChar;
|
||||||
TokenLength: integer;
|
TokenLength: integer;
|
||||||
TokenAttr: TSynHighlighterAttributes;
|
TokenAttr: TLazCustomEditTextAttribute;
|
||||||
TokenOrigin: TLazSynDisplayTokenOrigin;
|
TokenOrigin: TLazSynDisplayTokenOrigin;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ end;
|
|||||||
function TLazSynPaintTokenBreaker.GetNextHighlighterTokenFromView(out
|
function TLazSynPaintTokenBreaker.GetNextHighlighterTokenFromView(out
|
||||||
ATokenInfo: TLazSynDisplayTokenInfoEx; APhysEnd: Integer; ALogEnd: Integer): Boolean;
|
ATokenInfo: TLazSynDisplayTokenInfoEx; APhysEnd: Integer; ALogEnd: Integer): Boolean;
|
||||||
|
|
||||||
procedure InitSynAttr(var ATarget: TSynSelectedColorMergeResult; const ASource: TLazEditTextAttribute;
|
procedure InitSynAttr(var ATarget: TSynSelectedColorMergeResult; const ASource: TLazCustomEditTextAttribute;
|
||||||
const AnAttrStartX: TLazSynDisplayTokenBound);
|
const AnAttrStartX: TLazSynDisplayTokenBound);
|
||||||
const
|
const
|
||||||
NoEnd: TLazSynDisplayTokenBound = (Physical: -1; Logical: -1; Offset: 0);
|
NoEnd: TLazSynDisplayTokenBound = (Physical: -1; Logical: -1; Offset: 0);
|
||||||
@ -539,7 +539,6 @@ function TLazSynPaintTokenBreaker.GetNextHighlighterTokenFromView(out
|
|||||||
ATarget.Style := []; // Font.Style; // currently always cleared
|
ATarget.Style := []; // Font.Style; // currently always cleared
|
||||||
end;
|
end;
|
||||||
// ATarget.MergeFinalStyle := True;
|
// ATarget.MergeFinalStyle := True;
|
||||||
ATarget.StyleMask := [];
|
|
||||||
ATarget.StartX := AnAttrStartX;
|
ATarget.StartX := AnAttrStartX;
|
||||||
ATarget.EndX := NoEnd;
|
ATarget.EndX := NoEnd;
|
||||||
end;
|
end;
|
||||||
|
@ -52,7 +52,7 @@ uses
|
|||||||
SynEditHighlighter, SynEditTextBase, SynEditTextBuffer,
|
SynEditHighlighter, SynEditTextBase, SynEditTextBuffer,
|
||||||
FileUtil, LazUTF8, FPCAdds, LCLType,
|
FileUtil, LazUTF8, FPCAdds, LCLType,
|
||||||
Graphics, Clipbrd,
|
Graphics, Clipbrd,
|
||||||
SynEditMiscProcs, SynEditStrConst;
|
SynEditMiscProcs, SynEditStrConst, LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
PSynReplaceCharsArray = ^TSynReplaceCharsArray;
|
PSynReplaceCharsArray = ^TSynReplaceCharsArray;
|
||||||
@ -126,13 +126,13 @@ type
|
|||||||
token into account }
|
token into account }
|
||||||
procedure FormatBeforeFirstAttributeImmediate(BG, FG: TColor); virtual; abstract;
|
procedure FormatBeforeFirstAttributeImmediate(BG, FG: TColor); virtual; abstract;
|
||||||
procedure FormatAfterLastAttributeImmediate; virtual; abstract;
|
procedure FormatAfterLastAttributeImmediate; virtual; abstract;
|
||||||
procedure FormatAttributeInitImmediate(Attri: TSynHighlighterAttributes; IsSpace: Boolean); virtual; abstract;
|
procedure FormatAttributeInitImmediate(Attri: TLazCustomEditTextAttribute; IsSpace: Boolean); virtual; abstract;
|
||||||
procedure FormatAttributeDoneImmediate(Attri: TSynHighlighterAttributes; IsSpace: Boolean); virtual; abstract;
|
procedure FormatAttributeDoneImmediate(Attri: TLazCustomEditTextAttribute; IsSpace: Boolean); virtual; abstract;
|
||||||
|
|
||||||
{ Has to be overridden in descendant classes to add the formatted text of
|
{ Has to be overridden in descendant classes to add the formatted text of
|
||||||
the actual token text to the output buffer. }
|
the actual token text to the output buffer. }
|
||||||
procedure FormatToken(Token: string); virtual;
|
procedure FormatToken(Token: string); virtual;
|
||||||
procedure FormatTokenImmediate(Token: String; Attri: TSynHighlighterAttributes; IsSpace: Boolean);
|
procedure FormatTokenImmediate(Token: String; Attri: TLazCustomEditTextAttribute; IsSpace: Boolean);
|
||||||
{ Has to be overridden in descendant classes to add a newline in the output
|
{ Has to be overridden in descendant classes to add a newline in the output
|
||||||
format to the output buffer. }
|
format to the output buffer. }
|
||||||
procedure FormatNewLine; virtual; abstract;
|
procedure FormatNewLine; virtual; abstract;
|
||||||
@ -166,7 +166,7 @@ type
|
|||||||
of colors and font styles so the properties of the next token can be
|
of colors and font styles so the properties of the next token can be
|
||||||
added to the output buffer. }
|
added to the output buffer. }
|
||||||
procedure SetTokenAttribute(IsSpace: boolean;
|
procedure SetTokenAttribute(IsSpace: boolean;
|
||||||
Attri: TSynHighlighterAttributes); virtual;
|
Attri: TLazCustomEditTextAttribute); virtual;
|
||||||
function ValidatedColor(AColor, ADefColor: TColor): TColor;
|
function ValidatedColor(AColor, ADefColor: TColor): TColor;
|
||||||
public
|
public
|
||||||
{ Creates an instance of the exporter. }
|
{ Creates an instance of the exporter. }
|
||||||
@ -304,7 +304,7 @@ var
|
|||||||
i, X, l: integer;
|
i, X, l: integer;
|
||||||
Token: string;
|
Token: string;
|
||||||
IsSpace: boolean;
|
IsSpace: boolean;
|
||||||
Attri: TSynHighlighterAttributes;
|
Attri: TLazCustomEditTextAttribute;
|
||||||
TheLines: TSynEditStringsBase;
|
TheLines: TSynEditStringsBase;
|
||||||
begin
|
begin
|
||||||
// abort if not all necessary conditions are met
|
// abort if not all necessary conditions are met
|
||||||
@ -344,7 +344,7 @@ begin
|
|||||||
Highlighter.StartAtLineIndex(i - 1);
|
Highlighter.StartAtLineIndex(i - 1);
|
||||||
X := 1;
|
X := 1;
|
||||||
while not Highlighter.GetEOL do begin
|
while not Highlighter.GetEOL do begin
|
||||||
Attri := Highlighter.GetTokenAttribute;
|
Attri := Highlighter.GetTokenAttributeEx;
|
||||||
Token := Highlighter.GetToken;
|
Token := Highlighter.GetToken;
|
||||||
l := UTF8Length(Token);
|
l := UTF8Length(Token);
|
||||||
|
|
||||||
@ -410,7 +410,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynCustomExporter.FormatTokenImmediate(Token: String;
|
procedure TSynCustomExporter.FormatTokenImmediate(Token: String;
|
||||||
Attri: TSynHighlighterAttributes; IsSpace: Boolean);
|
Attri: TLazCustomEditTextAttribute; IsSpace: Boolean);
|
||||||
begin
|
begin
|
||||||
{$ifdef debug_synexport}
|
{$ifdef debug_synexport}
|
||||||
debugln(['TSynCustomExporter.FormatTokenImmediate: Token = "', Token,'", IsSpace = ',IsSpace]);
|
debugln(['TSynCustomExporter.FormatTokenImmediate: Token = "', Token,'", IsSpace = ',IsSpace]);
|
||||||
@ -564,7 +564,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynCustomExporter.SetTokenAttribute(IsSpace: boolean;
|
procedure TSynCustomExporter.SetTokenAttribute(IsSpace: boolean;
|
||||||
Attri: TSynHighlighterAttributes);
|
Attri: TLazCustomEditTextAttribute);
|
||||||
var
|
var
|
||||||
ChangedBG: boolean;
|
ChangedBG: boolean;
|
||||||
ChangedFG: boolean;
|
ChangedFG: boolean;
|
||||||
|
@ -54,7 +54,7 @@ uses
|
|||||||
// SynEdit
|
// SynEdit
|
||||||
LazSynEditText, SynEditTypes, SynEditMiscClasses, SynEditMiscProcs,
|
LazSynEditText, SynEditTypes, SynEditMiscClasses, SynEditMiscProcs,
|
||||||
SynEditPointClasses, SynEditHighlighter, SynEditHighlighterFoldBase,
|
SynEditPointClasses, SynEditHighlighter, SynEditHighlighterFoldBase,
|
||||||
SynEditKeyCmds;
|
SynEditKeyCmds, LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -758,7 +758,7 @@ const
|
|||||||
LSTATE_DOTS = 4; // In Dots
|
LSTATE_DOTS = 4; // In Dots
|
||||||
LSTATE_EOL = 5; // at start of EOL
|
LSTATE_EOL = 5; // at start of EOL
|
||||||
var
|
var
|
||||||
EolAttr: TSynHighlighterAttributes;
|
EolAttr: TLazCustomEditTextAttribute;
|
||||||
MergeStartX, MergeEndX: TLazSynDisplayTokenBound;
|
MergeStartX, MergeEndX: TLazSynDisplayTokenBound;
|
||||||
begin
|
begin
|
||||||
case FLineState of
|
case FLineState of
|
||||||
@ -772,7 +772,7 @@ begin
|
|||||||
ATokenInfo.TokenLength := 3;
|
ATokenInfo.TokenLength := 3;
|
||||||
ATokenInfo.TokenOrigin := dtoAfterText;
|
ATokenInfo.TokenOrigin := dtoAfterText;
|
||||||
if Assigned(CurrentTokenHighlighter)
|
if Assigned(CurrentTokenHighlighter)
|
||||||
then EolAttr := CurrentTokenHighlighter.GetEndOfLineAttribute
|
then EolAttr := CurrentTokenHighlighter.GetEndOfLineAttributeEx
|
||||||
else EolAttr := nil;
|
else EolAttr := nil;
|
||||||
if EolAttr <> nil then begin
|
if EolAttr <> nil then begin
|
||||||
FTokenAttr.Assign(EolAttr);
|
FTokenAttr.Assign(EolAttr);
|
||||||
|
@ -304,8 +304,15 @@ type
|
|||||||
function GetRange: Pointer; virtual;
|
function GetRange: Pointer; virtual;
|
||||||
function GetToken: String; virtual; abstract;
|
function GetToken: String; virtual; abstract;
|
||||||
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); virtual; abstract;
|
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); virtual; abstract;
|
||||||
|
(* GetTokenAttribute / GetEndOfLineAttribute
|
||||||
|
The base attribute
|
||||||
|
* GetTokenAttributeEx / GetEndOfLineAttributeEx
|
||||||
|
The final attribute with merged modifiers (if HL has modifiers)
|
||||||
|
*)
|
||||||
function GetEndOfLineAttribute: TSynHighlighterAttributes; virtual; // valid after line was scanned to EOL
|
function GetEndOfLineAttribute: TSynHighlighterAttributes; virtual; // valid after line was scanned to EOL
|
||||||
|
function GetEndOfLineAttributeEx: TLazCustomEditTextAttribute; virtual; // valid after line was scanned to EOL
|
||||||
function GetTokenAttribute: TSynHighlighterAttributes; virtual; abstract;
|
function GetTokenAttribute: TSynHighlighterAttributes; virtual; abstract;
|
||||||
|
function GetTokenAttributeEx: TLazCustomEditTextAttribute; virtual;
|
||||||
function GetTokenKind: integer; virtual; abstract;
|
function GetTokenKind: integer; virtual; abstract;
|
||||||
function GetTokenPos: Integer; virtual; abstract; // 0-based
|
function GetTokenPos: Integer; virtual; abstract; // 0-based
|
||||||
function GetTokenLen: Integer; virtual;
|
function GetTokenLen: Integer; virtual;
|
||||||
@ -1140,6 +1147,16 @@ begin
|
|||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSynCustomHighlighter.GetEndOfLineAttributeEx: TLazCustomEditTextAttribute;
|
||||||
|
begin
|
||||||
|
Result := GetEndOfLineAttribute;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TSynCustomHighlighter.GetTokenAttributeEx: TLazCustomEditTextAttribute;
|
||||||
|
begin
|
||||||
|
Result := GetTokenAttribute;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynCustomHighlighter.GetTokenLen: Integer;
|
function TSynCustomHighlighter.GetTokenLen: Integer;
|
||||||
var
|
var
|
||||||
x: PChar;
|
x: PChar;
|
||||||
|
@ -499,7 +499,7 @@ type
|
|||||||
|
|
||||||
{ TSynSelectedColorMergeResult }
|
{ TSynSelectedColorMergeResult }
|
||||||
|
|
||||||
TSynSelectedColorMergeResult = class(TSynSelectedColor)
|
TSynSelectedColorMergeResult = class(TLazCustomEditTextAttribute)
|
||||||
private
|
private
|
||||||
// TSynSelectedColor.Style and StyleMask describe how to modify a style,
|
// TSynSelectedColor.Style and StyleMask describe how to modify a style,
|
||||||
// but PaintLines creates an instance that contains an actual style (without mask)
|
// but PaintLines creates an instance that contains an actual style (without mask)
|
||||||
@ -536,6 +536,7 @@ type
|
|||||||
ANoneColor: TColor; IsFrame: Boolean = False): TColor;
|
ANoneColor: TColor; IsFrame: Boolean = False): TColor;
|
||||||
property FrameSideOrigin[Side: TLazSynBorderSide]: TSynFrameEdges read GetFrameSideOrigin;
|
property FrameSideOrigin[Side: TLazSynBorderSide]: TSynFrameEdges read GetFrameSideOrigin;
|
||||||
public
|
public
|
||||||
|
constructor Create(ACaption: PString; AStoredName: String = ''); overload; deprecated 'use Create without name // To be removed in 5.99';
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
// boundaries for current paint
|
// boundaries for current paint
|
||||||
@ -1305,6 +1306,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TSynSelectedColorMergeResult.Create(ACaption: PString; AStoredName: String);
|
||||||
|
begin
|
||||||
|
Create;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TSynSelectedColorMergeResult.Destroy;
|
destructor TSynSelectedColorMergeResult.Destroy;
|
||||||
begin
|
begin
|
||||||
CleanupMergeInfo;
|
CleanupMergeInfo;
|
||||||
|
@ -423,14 +423,14 @@ begin
|
|||||||
if not Result then begin
|
if not Result then begin
|
||||||
ATokenInfo.TokenStart := nil;
|
ATokenInfo.TokenStart := nil;
|
||||||
ATokenInfo.TokenLength := 0;
|
ATokenInfo.TokenLength := 0;
|
||||||
ATokenInfo.TokenAttr := CurrentTokenHighlighter.GetEndOfLineAttribute;
|
ATokenInfo.TokenAttr := CurrentTokenHighlighter.GetEndOfLineAttributeEx;
|
||||||
ATokenInfo.TokenOrigin := dtoAfterText;
|
ATokenInfo.TokenOrigin := dtoAfterText;
|
||||||
Result := ATokenInfo.TokenAttr <> nil;
|
Result := ATokenInfo.TokenAttr <> nil;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
CurrentTokenHighlighter.GetTokenEx(ATokenInfo.TokenStart, ATokenInfo.TokenLength);
|
CurrentTokenHighlighter.GetTokenEx(ATokenInfo.TokenStart, ATokenInfo.TokenLength);
|
||||||
ATokenInfo.TokenAttr := CurrentTokenHighlighter.GetTokenAttribute;
|
ATokenInfo.TokenAttr := CurrentTokenHighlighter.GetTokenAttributeEx;
|
||||||
ATokenInfo.TokenOrigin := dtoVirtualText;
|
ATokenInfo.TokenOrigin := dtoVirtualText;
|
||||||
CurrentTokenHighlighter.Next;
|
CurrentTokenHighlighter.Next;
|
||||||
end;
|
end;
|
||||||
|
@ -47,7 +47,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
LCLIntf, LCLType, Graphics, ClipBrd,
|
LCLIntf, LCLType, Graphics, ClipBrd,
|
||||||
SynEditHighlighter, SynEditExport, LazUtf8, SynEditStrConst;
|
SynEditHighlighter, SynEditExport, LazUtf8, SynEditStrConst, LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
THTMLFontSize = (fs01, fs02, fs03, fs04, fs05, fs06, fs07, fsDefault); //eb 2000-10-12
|
THTMLFontSize = (fs01, fs02, fs03, fs04, fs05, fs06, fs07, fsDefault); //eb 2000-10-12
|
||||||
@ -84,8 +84,8 @@ type
|
|||||||
{end} //mh 2000-10-10
|
{end} //mh 2000-10-10
|
||||||
procedure FormatBeforeFirstAttributeImmediate(BG, FG: TColor); override;
|
procedure FormatBeforeFirstAttributeImmediate(BG, FG: TColor); override;
|
||||||
procedure FormatAfterLastAttributeImmediate; override;
|
procedure FormatAfterLastAttributeImmediate; override;
|
||||||
procedure FormatAttributeInitImmediate(Attri: TSynHighlighterAttributes; IsSpace: Boolean); override;
|
procedure FormatAttributeInitImmediate(Attri: TLazCustomEditTextAttribute; IsSpace: Boolean); override;
|
||||||
procedure FormatAttributeDoneImmediate(Attri: TSynHighlighterAttributes; IsSpace: Boolean); override;
|
procedure FormatAttributeDoneImmediate(Attri: TLazCustomEditTextAttribute; IsSpace: Boolean); override;
|
||||||
|
|
||||||
procedure FormatNewLine; override;
|
procedure FormatNewLine; override;
|
||||||
function GetFooter: string; override;
|
function GetFooter: string; override;
|
||||||
@ -404,7 +404,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynExporterHTML.FormatAttributeInitImmediate(
|
procedure TSynExporterHTML.FormatAttributeInitImmediate(
|
||||||
Attri: TSynHighlighterAttributes; IsSpace: Boolean);
|
Attri: TLazCustomEditTextAttribute; IsSpace: Boolean);
|
||||||
var
|
var
|
||||||
Span, StyleStr: String;
|
Span, StyleStr: String;
|
||||||
FG, BG: TColor;
|
FG, BG: TColor;
|
||||||
@ -428,7 +428,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynExporterHTML.FormatAttributeDoneImmediate(
|
procedure TSynExporterHTML.FormatAttributeDoneImmediate(
|
||||||
Attri: TSynHighlighterAttributes; IsSpace: Boolean);
|
Attri: TLazCustomEditTextAttribute; IsSpace: Boolean);
|
||||||
var
|
var
|
||||||
FG, BG: TColor;
|
FG, BG: TColor;
|
||||||
StyleStr: String;
|
StyleStr: String;
|
||||||
|
@ -53,7 +53,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, Graphics, SysUtils, Math, RegExpr,
|
Classes, Graphics, SysUtils, Math, RegExpr,
|
||||||
SynEditStrConst, SynEditTypes, SynEditTextBase,
|
SynEditStrConst, SynEditTypes, SynEditTextBase,
|
||||||
SynEditHighlighter,
|
SynEditHighlighter, LazEditTextAttributes,
|
||||||
{$IFDEF SynDebugMultiHL}LazLoggerBase{$ELSE}LazLoggerDummy{$ENDIF}, LazUTF8
|
{$IFDEF SynDebugMultiHL}LazLoggerBase{$ELSE}LazLoggerDummy{$ENDIF}, LazUTF8
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -289,6 +289,7 @@ type
|
|||||||
FTokenPos: integer;
|
FTokenPos: integer;
|
||||||
FTokenKind: integer;
|
FTokenKind: integer;
|
||||||
FTokenAttr: TSynHighlighterAttributes;
|
FTokenAttr: TSynHighlighterAttributes;
|
||||||
|
FTokenAttrEx: TLazCustomEditTextAttribute;
|
||||||
FRun: Integer;
|
FRun: Integer;
|
||||||
FRunSectionInfo: Array of TRunSectionInfo;
|
FRunSectionInfo: Array of TRunSectionInfo;
|
||||||
FSampleSource: string;
|
FSampleSource: string;
|
||||||
@ -322,6 +323,7 @@ type
|
|||||||
function GetToken: string; override;
|
function GetToken: string; override;
|
||||||
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
|
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
|
||||||
function GetTokenAttribute: TSynHighlighterAttributes; override;
|
function GetTokenAttribute: TSynHighlighterAttributes; override;
|
||||||
|
function GetTokenAttributeEx: TLazCustomEditTextAttribute; override;
|
||||||
function GetTokenKind: integer; override;
|
function GetTokenKind: integer; override;
|
||||||
function GetTokenPos: Integer; override; // 0-based
|
function GetTokenPos: Integer; override; // 0-based
|
||||||
procedure SetLine(const NewValue: string; LineNumber: Integer); override;
|
procedure SetLine(const NewValue: string; LineNumber: Integer); override;
|
||||||
@ -1356,6 +1358,11 @@ begin
|
|||||||
Result := FTokenAttr;
|
Result := FTokenAttr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSynMultiSyn.GetTokenAttributeEx: TLazCustomEditTextAttribute;
|
||||||
|
begin
|
||||||
|
Result := FTokenAttrEx;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynMultiSyn.GetTokenKind: integer;
|
function TSynMultiSyn.GetTokenKind: integer;
|
||||||
begin
|
begin
|
||||||
Result := FTokenKind;
|
Result := FTokenKind;
|
||||||
@ -1430,6 +1437,7 @@ begin
|
|||||||
//debugln(['--- Next at ',FRun]);
|
//debugln(['--- Next at ',FRun]);
|
||||||
FTokenPos := FRun;
|
FTokenPos := FRun;
|
||||||
FTokenAttr := nil;
|
FTokenAttr := nil;
|
||||||
|
FTokenAttrEx := nil;
|
||||||
FTokenKind := 0;
|
FTokenKind := 0;
|
||||||
if FRun > FLineLen then
|
if FRun > FLineLen then
|
||||||
exit;
|
exit;
|
||||||
@ -1445,8 +1453,6 @@ begin
|
|||||||
if idx < 0 then begin
|
if idx < 0 then begin
|
||||||
//debugln(['*** XXXXX No section found XXXXX ***']);
|
//debugln(['*** XXXXX No section found XXXXX ***']);
|
||||||
FRun := FLineLen + 1;
|
FRun := FLineLen + 1;
|
||||||
FTokenAttr := nil;
|
|
||||||
FTokenKind := 0;
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1455,19 +1461,19 @@ begin
|
|||||||
if RSect.SectionIdx < 0 then begin
|
if RSect.SectionIdx < 0 then begin
|
||||||
//debugln(['*** XXXXX section missing XXXXX ***']);
|
//debugln(['*** XXXXX section missing XXXXX ***']);
|
||||||
FRun := FLineLen + 1;
|
FRun := FLineLen + 1;
|
||||||
FTokenAttr := nil;
|
|
||||||
FTokenKind := 0;
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (idx > 0) and (FRun < RSect.FirstChar) then begin
|
if (idx > 0) and (FRun < RSect.FirstChar) then begin
|
||||||
FTokenAttr := Schemes[idx-1].FMarkerAttri;
|
FTokenAttr := Schemes[idx-1].FMarkerAttri;
|
||||||
|
FTokenAttrEx := FTokenAttr;
|
||||||
FTokenKind := 1;
|
FTokenKind := 1;
|
||||||
FRun := RSect.FirstChar;
|
FRun := RSect.FirstChar;
|
||||||
//debugln([' start-token ', FRun]);
|
//debugln([' start-token ', FRun]);
|
||||||
end
|
end
|
||||||
else if (idx > 0) and (FRun > RSect.LastChar) then begin
|
else if (idx > 0) and (FRun > RSect.LastChar) then begin
|
||||||
FTokenAttr := Schemes[idx-1].FMarkerAttri;
|
FTokenAttr := Schemes[idx-1].FMarkerAttri;
|
||||||
|
FTokenAttrEx := FTokenAttr;
|
||||||
FTokenKind := 1;
|
FTokenKind := 1;
|
||||||
FRun := RSect.TokenLastChar + 1;
|
FRun := RSect.TokenLastChar + 1;
|
||||||
//debugln([' end-token ', FRun]);
|
//debugln([' end-token ', FRun]);
|
||||||
@ -1490,6 +1496,7 @@ begin
|
|||||||
until HL.GetEol;
|
until HL.GetEol;
|
||||||
if not HL.GetEol then begin
|
if not HL.GetEol then begin
|
||||||
FTokenAttr := HL.GetTokenAttribute;
|
FTokenAttr := HL.GetTokenAttribute;
|
||||||
|
FTokenAttrEx := HL.GetTokenAttributeEx;
|
||||||
FTokenKind := idx * TokenKindPerHighlighter + HL.GetTokenKind;
|
FTokenKind := idx * TokenKindPerHighlighter + HL.GetTokenKind;
|
||||||
FRun := Min(tkpos - RSect.VirtualStartPos + RSect.FirstChar + tklen,
|
FRun := Min(tkpos - RSect.VirtualStartPos + RSect.FirstChar + tklen,
|
||||||
RSect.LastChar + 1);
|
RSect.LastChar + 1);
|
||||||
@ -1501,6 +1508,7 @@ begin
|
|||||||
|
|
||||||
if (HL = nil) then begin
|
if (HL = nil) then begin
|
||||||
FTokenAttr := nil;
|
FTokenAttr := nil;
|
||||||
|
FTokenAttrEx := nil;
|
||||||
FTokenKind := 0;
|
FTokenKind := 0;
|
||||||
FRun := RSect.LastChar + 1;
|
FRun := RSect.LastChar + 1;
|
||||||
//debugln([' no HL ', FRun]);
|
//debugln([' no HL ', FRun]);
|
||||||
@ -1673,6 +1681,7 @@ begin
|
|||||||
fRun := 1;
|
fRun := 1;
|
||||||
FTokenPos := 1;
|
FTokenPos := 1;
|
||||||
FTokenAttr := nil;
|
FTokenAttr := nil;
|
||||||
|
FTokenAttrEx := nil;
|
||||||
FTokenKind := 0;
|
FTokenKind := 0;
|
||||||
//debugln(['>>>>> Setting Line ',FCurLineIndex,' = ',FLine]);
|
//debugln(['>>>>> Setting Line ',FCurLineIndex,' = ',FLine]);
|
||||||
for i := 0 to high(FRunSectionInfo) do
|
for i := 0 to high(FRunSectionInfo) do
|
||||||
|
@ -53,8 +53,9 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Classes, fgl, Registry, Graphics, Generics.Defaults, SynEditHighlighterFoldBase,
|
SysUtils, Classes, fgl, Registry, Graphics, Generics.Defaults, SynEditHighlighterFoldBase,
|
||||||
SynEditMiscProcs, SynEditTypes, SynEditHighlighter, SynEditTextBase,
|
SynEditMiscProcs, SynEditTypes, SynEditHighlighter, SynEditTextBase, SynEditStrConst,
|
||||||
SynEditStrConst, SynEditMiscClasses, LazLoggerBase, LazEditMiscProcs, LazEditHighlighterUtils;
|
SynEditMiscClasses, LazLoggerBase, LazEditMiscProcs, LazEditHighlighterUtils,
|
||||||
|
LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
TSynPasStringMode = (spsmDefault, spsmStringOnly, spsmNone);
|
TSynPasStringMode = (spsmDefault, spsmStringOnly, spsmNone);
|
||||||
@ -950,6 +951,7 @@ type
|
|||||||
function GetToken: string; override;
|
function GetToken: string; override;
|
||||||
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
|
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
|
||||||
function GetTokenAttribute: TSynHighlighterAttributes; override;
|
function GetTokenAttribute: TSynHighlighterAttributes; override;
|
||||||
|
function GetTokenAttributeEx: TLazCustomEditTextAttribute; override;
|
||||||
function GetTokenID: TtkTokenKind;
|
function GetTokenID: TtkTokenKind;
|
||||||
function GetTokenKind: integer; override;
|
function GetTokenKind: integer; override;
|
||||||
function GetTokenPos: Integer; override;
|
function GetTokenPos: Integer; override;
|
||||||
@ -3950,10 +3952,7 @@ begin
|
|||||||
AddAttribute(FCommentSlashAttri);
|
AddAttribute(FCommentSlashAttri);
|
||||||
FIDEDirectiveAttri := TSynHighlighterAttributesModifier.Create(@SYNS_AttrIDEDirective, SYNS_XML_AttrIDEDirective);
|
FIDEDirectiveAttri := TSynHighlighterAttributesModifier.Create(@SYNS_AttrIDEDirective, SYNS_XML_AttrIDEDirective);
|
||||||
AddAttribute(FIDEDirectiveAttri);
|
AddAttribute(FIDEDirectiveAttri);
|
||||||
// FCurIDEDirectiveAttri, FCurCaseLabelAttri, FCurProcTypeDeclExtraAttr
|
FCurIDEDirectiveAttri := TSynSelectedColorMergeResult.Create;
|
||||||
// They are not available through the "Attribute" property (not added via AddAttribute
|
|
||||||
// But they are returned via GetTokenAttribute, so they should have a name.
|
|
||||||
FCurIDEDirectiveAttri := TSynSelectedColorMergeResult.Create(@SYNS_AttrIDEDirective, SYNS_XML_AttrIDEDirective);
|
|
||||||
fIdentifierAttri := TSynHighlighterAttributes.Create(@SYNS_AttrIdentifier, SYNS_XML_AttrIdentifier);
|
fIdentifierAttri := TSynHighlighterAttributes.Create(@SYNS_AttrIdentifier, SYNS_XML_AttrIdentifier);
|
||||||
AddAttribute(fIdentifierAttri);
|
AddAttribute(fIdentifierAttri);
|
||||||
fKeyAttri := TSynHighlighterAttributes.Create(@SYNS_AttrReservedWord, SYNS_XML_AttrReservedWord);
|
fKeyAttri := TSynHighlighterAttributes.Create(@SYNS_AttrReservedWord, SYNS_XML_AttrReservedWord);
|
||||||
@ -5720,21 +5719,13 @@ begin
|
|||||||
Result := fTokenId;
|
Result := fTokenId;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TSynPasSyn.GetTokenAttribute: TSynHighlighterAttributes;
|
function TSynPasSyn.GetTokenAttribute: TSynHighlighterAttributes;
|
||||||
var
|
|
||||||
tid: TtkTokenKind;
|
|
||||||
i: Integer;
|
|
||||||
attr: TSynHighlighterAttributesModifier;
|
|
||||||
begin
|
begin
|
||||||
tid := GetTokenID;
|
case GetTokenID of
|
||||||
case tid of
|
|
||||||
tkAsm: Result := fAsmAttri;
|
tkAsm: Result := fAsmAttri;
|
||||||
tkComment: Result := fCommentAttri;
|
tkIDEDirective, tkComment:
|
||||||
tkIDEDirective: begin
|
Result := fCommentAttri;
|
||||||
FCurIDEDirectiveAttri.Assign(FCommentAttri);
|
|
||||||
FCurIDEDirectiveAttri.Merge(FIDEDirectiveAttri);
|
|
||||||
Result := FCurIDEDirectiveAttri;
|
|
||||||
end;
|
|
||||||
tkIdentifier: begin
|
tkIdentifier: begin
|
||||||
if eaGotoLabel in FTokenExtraAttribs then
|
if eaGotoLabel in FTokenExtraAttribs then
|
||||||
Result := FGotoLabelAttr
|
Result := FGotoLabelAttr
|
||||||
@ -5751,9 +5742,25 @@ begin
|
|||||||
tkUnknown: Result := fSymbolAttri;
|
tkUnknown: Result := fSymbolAttri;
|
||||||
else
|
else
|
||||||
Result := nil;
|
Result := nil;
|
||||||
exit; // can't merge
|
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
function TSynPasSyn.GetTokenAttributeEx: TLazCustomEditTextAttribute;
|
||||||
|
var
|
||||||
|
tid: TtkTokenKind;
|
||||||
|
i: Integer;
|
||||||
|
attr: TSynHighlighterAttributesModifier;
|
||||||
|
begin
|
||||||
|
Result := GetTokenAttribute;
|
||||||
|
if Result = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
tid := GetTokenID;
|
||||||
|
|
||||||
|
if tid = tkIDEDirective then begin
|
||||||
|
FCurIDEDirectiveAttri.Assign(FCommentAttri);
|
||||||
|
FCurIDEDirectiveAttri.Merge(FIDEDirectiveAttri);
|
||||||
|
Result := FCurIDEDirectiveAttri;
|
||||||
|
end;
|
||||||
|
|
||||||
if FTokenIsCaseLabel and
|
if FTokenIsCaseLabel and
|
||||||
( (tid in [tkIdentifier, tkNumber, tkString]) or
|
( (tid in [tkIdentifier, tkNumber, tkString]) or
|
||||||
|
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, TestBase, SynEdit, SynEditHighlighterFoldBase, SynEditHighlighter,
|
SysUtils, TestBase, SynEdit, SynEditHighlighterFoldBase, SynEditHighlighter,
|
||||||
SynEditMiscClasses, LazLoggerBase;
|
SynEditMiscClasses, LazLoggerBase, LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ end;
|
|||||||
procedure TTestBaseHighlighterFoldBase.CheckTokensForLine(Name: String;
|
procedure TTestBaseHighlighterFoldBase.CheckTokensForLine(Name: String;
|
||||||
LineIdx: Integer; ExpTokens: array of TExpTokenInfo);
|
LineIdx: Integer; ExpTokens: array of TExpTokenInfo);
|
||||||
|
|
||||||
function AttrVal(a: TSynHighlighterAttributes): Integer;
|
function AttrVal(a: TLazCustomEditTextAttribute): Integer;
|
||||||
begin
|
begin
|
||||||
if a = nil then exit(-1);
|
if a = nil then exit(-1);
|
||||||
if a is TSynSelectedColorMergeResult then
|
if a is TSynSelectedColorMergeResult then
|
||||||
@ -208,7 +208,7 @@ procedure TTestBaseHighlighterFoldBase.CheckTokensForLine(Name: String;
|
|||||||
var
|
var
|
||||||
c: Integer;
|
c: Integer;
|
||||||
e: TExpTokenInfo;
|
e: TExpTokenInfo;
|
||||||
GotAttr: TSynHighlighterAttributes;
|
GotAttr: TLazCustomEditTextAttribute;
|
||||||
begin
|
begin
|
||||||
FTheHighLighter.StartAtLineIndex(LineIdx);
|
FTheHighLighter.StartAtLineIndex(LineIdx);
|
||||||
c := 0;
|
c := 0;
|
||||||
@ -224,7 +224,7 @@ begin
|
|||||||
AssertEquals(Name + ' ASSERT token-kind @ TokenId Line='+IntToStr(LineIdx)+' pos='+IntToStr(c)+' Src='+FTheHighLighter.GetToken+' @'+IntToStr(FTheHighLighter.GetTokenPos),
|
AssertEquals(Name + ' ASSERT token-kind @ TokenId Line='+IntToStr(LineIdx)+' pos='+IntToStr(c)+' Src='+FTheHighLighter.GetToken+' @'+IntToStr(FTheHighLighter.GetTokenPos),
|
||||||
e.ExpKind, FTheHighLighter.GetTokenKind);
|
e.ExpKind, FTheHighLighter.GetTokenKind);
|
||||||
|
|
||||||
GotAttr := FTheHighLighter.GetTokenAttribute;
|
GotAttr := FTheHighLighter.GetTokenAttributeEx;
|
||||||
if etiAttr in e.Flags then
|
if etiAttr in e.Flags then
|
||||||
AssertEquals(Name + ' Attr @ TokenId Line='+IntToStr(LineIdx)+' pos='+IntToStr(c)+' Src='+FTheHighLighter.GetToken+' @'+IntToStr(FTheHighLighter.GetTokenPos),
|
AssertEquals(Name + ' Attr @ TokenId Line='+IntToStr(LineIdx)+' pos='+IntToStr(c)+' Src='+FTheHighLighter.GetToken+' @'+IntToStr(FTheHighLighter.GetTokenPos),
|
||||||
AttrVal(e.ExpAttr), AttrVal(GotAttr))
|
AttrVal(e.ExpAttr), AttrVal(GotAttr))
|
||||||
|
@ -7,7 +7,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, Math, testregistry, TestBase, Forms, SynEditHighlighter,
|
Classes, SysUtils, Math, testregistry, TestBase, Forms, SynEditHighlighter,
|
||||||
SynHighlighterMulti, SynHighlighterLFM, SynHighlighterXML, SynHighlighterPas, SynEditKeyCmds,
|
SynHighlighterMulti, SynHighlighterLFM, SynHighlighterXML, SynHighlighterPas, SynEditKeyCmds,
|
||||||
LazSynEditText, SynEditTextBuffer, SynEditTypes, LazLoggerBase;
|
LazSynEditText, SynEditTextBuffer, SynEditTypes, LazLoggerBase, LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ procedure TTestHighlightMulti.CheckTokensForLine(Name: String; HL: TSynCustomHig
|
|||||||
LineIdx: Integer; ExpAttr: array of TSynHighlighterAttributes);
|
LineIdx: Integer; ExpAttr: array of TSynHighlighterAttributes);
|
||||||
var
|
var
|
||||||
c: Integer;
|
c: Integer;
|
||||||
tk: TSynHighlighterAttributes;
|
tk: TLazCustomEditTextAttribute;
|
||||||
tkName: String;
|
tkName: String;
|
||||||
begin
|
begin
|
||||||
HL.StartAtLineIndex(LineIdx);
|
HL.StartAtLineIndex(LineIdx);
|
||||||
@ -275,9 +275,9 @@ begin
|
|||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
//DebugLn([HL.GetToken,' (',HL.GetTokenID ,') at ', HL.GetTokenPos]);
|
//DebugLn([HL.GetToken,' (',HL.GetTokenID ,') at ', HL.GetTokenPos]);
|
||||||
tk := HL.GetTokenAttribute;
|
tk := HL.GetTokenAttributeEx;
|
||||||
if tk <> nil
|
if (tk <> nil) and (tk is TSynHighlighterAttributes)
|
||||||
then tkName := tk.StoredName
|
then tkName := TSynHighlighterAttributes(tk).StoredName
|
||||||
else tkName := '<nil>';
|
else tkName := '<nil>';
|
||||||
AssertTrue(Format('%s Attrib Line=%d pos=%d exp=%s got=%s',
|
AssertTrue(Format('%s Attrib Line=%d pos=%d exp=%s got=%s',
|
||||||
[Name, LineIdx, c, ExpAttr[c].StoredName, tkName]),
|
[Name, LineIdx, c, ExpAttr[c].StoredName, tkName]),
|
||||||
|
@ -50,7 +50,8 @@ uses
|
|||||||
// IdeIntf
|
// IdeIntf
|
||||||
LazIDEIntf, IDEImagesIntf, TextTools, IDETextConverter,
|
LazIDEIntf, IDEImagesIntf, TextTools, IDETextConverter,
|
||||||
// IDE
|
// IDE
|
||||||
DialogProcs, EditorOptions, CodeToolsOptions, SourceSynEditor, SourceMarks;
|
DialogProcs, EditorOptions, CodeToolsOptions, SourceSynEditor, SourceMarks,
|
||||||
|
LazEditTextAttributes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -276,7 +277,7 @@ var
|
|||||||
var
|
var
|
||||||
sToken: PChar;
|
sToken: PChar;
|
||||||
nTokenLen: integer;
|
nTokenLen: integer;
|
||||||
Attr: TSynHighlightElement;
|
Attr: TLazCustomEditTextAttribute;
|
||||||
CurForeground: TColor;
|
CurForeground: TColor;
|
||||||
LeftText: string;
|
LeftText: string;
|
||||||
begin
|
begin
|
||||||
@ -293,7 +294,7 @@ var
|
|||||||
SetLength(s,nTokenLen);
|
SetLength(s,nTokenLen);
|
||||||
if nTokenLen>0 then begin
|
if nTokenLen>0 then begin
|
||||||
System.Move(sToken^,s[1],nTokenLen);
|
System.Move(sToken^,s[1],nTokenLen);
|
||||||
attr := Highlighter.GetTokenAttribute;
|
attr := Highlighter.GetTokenAttributeEx;
|
||||||
CurForeground:=Attr.Foreground;
|
CurForeground:=Attr.Foreground;
|
||||||
if CurForeground=clNone then
|
if CurForeground=clNone then
|
||||||
CurForeground:=TColor(ForegroundColor);
|
CurForeground:=TColor(ForegroundColor);
|
||||||
|
Loading…
Reference in New Issue
Block a user