On 05/11/2013 10:59, Martin wrote:
On 05/11/2013 10:36, Zaher Dirkey wrote:
Hi,
Is it possible when set a background color of the comment (for
example) to highlight the full line to make it prettier.
I am not talking in LazarusIDE, it is in SynEdit because I use it in
my project 'miniedit'.
Not currently.
Needs to be implemented.
Currently TLazSynPaintTokenBreaker.GetNextHighlighterTokenEx generates
a dummy token for the end of line. It would need to get the info from
the HIghlighter.
Try attached patch.
Index: components/synedit/lazsyntextarea.pp
===================================================================
--- components/synedit/lazsyntextarea.pp (revision 43374)
+++ components/synedit/lazsyntextarea.pp (working copy)
@@ -383,8 +383,13 @@
ATokenInfo.PhysicalClipEnd := ATokenInfo.EndPos.Physical;
ATokenInfo.RtlInfo.IsRtl := False;
FMarkupTokenAttr.Clear;
- FMarkupTokenAttr.Foreground := FForegroundColor;
- FMarkupTokenAttr.Background := FBackgroundColor;
+ if ATokenInfo.Attr <> nil then begin
+ FMarkupTokenAttr.Assign(ATokenInfo.Attr);
+ end
+ else begin
+ FMarkupTokenAttr.Foreground := FForegroundColor;
+ FMarkupTokenAttr.Background := FBackgroundColor;
+ end;
ATokenInfo.ExpandedExtraBytes := 0;
ATokenInfo.HasTabs := False;
@@ -456,6 +461,9 @@
FCurViewCurTokenStartPos := FCurViewScannerPos;
while FCurViewToken.TokenLength = 0 do begin // Todo: is SyncroEd-test a zero size token is returned
Result := FDisplayView.GetNextHighlighterToken(FCurViewToken);
+ if not Result then
+ FCurViewToken.TokenAttr := nil;
+ Result := Result and (FCurViewToken.TokenStart <> nil); // False for end of line token
if not Result then begin
FCurViewToken.TokenLength := -1;
exit;
@@ -665,6 +673,12 @@
Result := MaybeFetchToken; // Get token from View/Highlighter
if not Result then begin
ATokenInfo.StartPos := FCurViewScannerPos;
+ if FCurViewToken.TokenAttr <> nil then begin
+ InitSynAttr(FCurViewAttr, FCurViewToken.TokenAttr, FCurViewCurTokenStartPos);
+ ATokenInfo.Attr := FCurViewAttr;
+ end
+ else
+ ATokenInfo.Attr := nil;
exit;
end;
Index: components/synedit/syneditfoldedview.pp
===================================================================
--- components/synedit/syneditfoldedview.pp (revision 43374)
+++ components/synedit/syneditfoldedview.pp (working copy)
@@ -809,7 +809,7 @@
case FLineState of
0: begin
Result := inherited GetNextHighlighterToken(ATokenInfo);
- if (not Result) and
+ if ( (not Result) or (ATokenInfo.TokenStart = nil)) and
(FFoldView.FoldType[CurrentTokenLine + 1 - FFoldView.TopLine] * [cfCollapsedFold, cfCollapsedHide] <> [])
then begin
inc(FLineState);
Index: components/synedit/synedithighlighter.pp
===================================================================
--- components/synedit/synedithighlighter.pp (revision 43374)
+++ components/synedit/synedithighlighter.pp (working copy)
@@ -372,7 +372,7 @@
function GetRange: Pointer; virtual;
function GetToken: String; virtual; abstract;
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); virtual; abstract;
- function GetEndOfLineAttribute: TSynHighlighterAttributes; virtual;
+ function GetEndOfLineAttribute: TSynHighlighterAttributes; virtual; // valid after line was scanned to EOL
function GetTokenAttribute: TSynHighlighterAttributes; virtual; abstract;
function GetTokenKind: integer; virtual; abstract;
function GetTokenPos: Integer; virtual; abstract; // 0-based
Index: components/synedit/synedittextbuffer.pp
===================================================================
--- components/synedit/synedittextbuffer.pp (revision 43374)
+++ components/synedit/synedittextbuffer.pp (working copy)
@@ -372,7 +372,13 @@
FAtLineStart := False;
Result := not CurrentTokenHighlighter.GetEol;
- if not Result then exit;
+ if not Result then begin
+ ATokenInfo.TokenStart := nil;
+ ATokenInfo.TokenLength := 0;
+ ATokenInfo.TokenAttr := CurrentTokenHighlighter.GetEndOfLineAttribute;
+ Result := ATokenInfo.TokenAttr <> nil;
+ exit;
+ end;
CurrentTokenHighlighter.GetTokenEx(ATokenInfo.TokenStart, ATokenInfo.TokenLength);
ATokenInfo.TokenAttr := CurrentTokenHighlighter.GetTokenAttribute;
Index: components/synedit/synhighlighterpas.pp
===================================================================
--- components/synedit/synhighlighterpas.pp (revision 43374)
+++ components/synedit/synhighlighterpas.pp (working copy)
@@ -533,6 +533,7 @@
procedure SetLine(const NewValue: string; LineNumber: Integer); override;
procedure SetRange(Value: Pointer); override;
procedure StartAtLineIndex(LineNumber:Integer); override; // 0 based
+ function GetEndOfLineAttribute: TSynHighlighterAttributes; override;
function UseUserSettings(settingIndex: integer): boolean; override;
procedure EnumUserSettings(settings: TStrings); override;
@@ -3133,6 +3134,14 @@
inherited StartAtLineIndex(LineNumber);
end;
+function TSynPasSyn.GetEndOfLineAttribute: TSynHighlighterAttributes;
+begin
+ if fRange * [rsAnsi, rsBor] <> [] then
+ Result := fCommentAttri
+ else
+ Result := inherited GetEndOfLineAttribute;
+end;
+
procedure TSynPasSyn.ResetRange;
begin
fRange := [];
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus