SynEdit: Markup fold color, if else chain / nesting based on indent, part of patch 20 from issue #30421 by Pascal R.

git-svn-id: trunk@54155 -
This commit is contained in:
martin 2017-02-14 20:00:04 +00:00
parent 5ef6c2591f
commit 8a827a4ea7

View File

@ -176,12 +176,13 @@ begin
MarkupInfo.StyleMask := []; MarkupInfo.StyleMask := [];
MarkupInfo.FrameEdges:= sfeLeft; MarkupInfo.FrameEdges:= sfeLeft;
SetLength(Colors, 5); SetLength(Colors, 6);
Colors[0] := clRed; Colors[0] := clRed;
Colors[1] := $000098F7; //orange Colors[1] := $000098F7; //orange
Colors[2] := $0022CC40; //green Colors[2] := $0022CC40; //green
Colors[3] := $00FF682A; //blue Colors[3] := $00CCCC00; //cyan
Colors[4] := $00CF00C4; //purple Colors[4] := $00FF682A; //blue
Colors[5] := $00CF00C4; //purple
end; end;
destructor TSynEditMarkupFoldColors.Destroy; destructor TSynEditMarkupFoldColors.Destroy;
@ -379,22 +380,22 @@ begin
inc(lvl) inc(lvl)
else if ( sfaOutlineMergeParent in TmpNode.FoldAction) then else if ( sfaOutlineMergeParent in TmpNode.FoldAction) then
dec(lvl); dec(lvl);
//if (FLastNode.LineIndex >= 0) if (FLastNode.LineIndex >= 0)
//and (sfaOutlineKeepLevelOnSameLine in FLastNode.FoldAction) and (sfaOutlineKeepLevel in FLastNode.FoldAction)
//and (FLastNode.LineIndex < TmpNode.LineIndex) then and (FLastNode.LineIndex < TmpNode.LineIndex) then
// inc(lvl); inc(lvl);
AddVerticalLine(TmpNode, i); AddVerticalLine(TmpNode, i);
//if (FFoldColorInfosCount - 1 > 0) if (FFoldColorInfosCount - 1 > 0)
//and (FFoldColorInfos[FFoldColorInfosCount - 1].X = FFoldColorInfos[FFoldColorInfosCount - 2].X) then begin and (FFoldColorInfos[FFoldColorInfosCount - 1].X = FFoldColorInfos[FFoldColorInfosCount - 2].X) then begin
// // if child is on same x-pos keep level // if child is on same x-pos keep level
// if sfaOutlineMergeLevelOnWrongCol in FFoldColorInfos[FFoldColorInfosCount - 1].SrcNode.FoldAction then begin if sfaOutlineKeepLevel in FFoldColorInfos[FFoldColorInfosCount - 2].SrcNode.FoldAction then begin
// lvl := FFoldColorInfos[FFoldColorInfosCount - 2].Level; lvl := FFoldColorInfos[FFoldColorInfosCount - 2].Level;
// FFoldColorInfos[FFoldColorInfosCount - 1].Level := lvl; FFoldColorInfos[FFoldColorInfosCount - 1].Level := lvl;
// FFoldColorInfos[FFoldColorInfosCount - 1].ColorIdx := Max(0, lvl) mod (length(Colors)); FFoldColorInfos[FFoldColorInfosCount - 1].ColorIdx := Max(0, lvl) mod (length(Colors));
// end; end;
//end; end;
if not (sfaOutlineKeepLevel in TmpNode.FoldAction) if not (sfaOutlineKeepLevel in TmpNode.FoldAction)
{and not (sfaOutlineKeepLevelOnSameLine in TmpNode.FoldAction)} then {and not (sfaOutlineKeepLevelOnSameLine in TmpNode.FoldAction)} then
@ -483,8 +484,8 @@ begin
TmpNode := NodeList[i]; TmpNode := NodeList[i];
{$IFDEF SynEditMarkupFoldColoringDebug} {$IFDEF SynEditMarkupFoldColoringDebug}
//if not (sfaInvalid in TmpNode.FoldAction) then if not (sfaInvalid in TmpNode.FoldAction) then
// DebugLn(' C: %s %s', [IfThen(sfaClose in TmpNode.FoldAction, 'C ', IfThen(sfaOpen in TmpNode.FoldAction, 'O ', '??')),FoldTypeToStr(TmpNode.FoldType)]); DebugLn(' C: %s %s %s', [IfThen(sfaOutline in TmpNode.FoldAction, 'X', '-'), IfThen(sfaClose in TmpNode.FoldAction, 'C ', IfThen(sfaOpen in TmpNode.FoldAction, 'O ', '??')),FoldTypeToStr(TmpNode.FoldType)]);
{$ENDIF} {$ENDIF}
if not (sfaInvalid in TmpNode.FoldAction) if not (sfaInvalid in TmpNode.FoldAction)
@ -496,28 +497,24 @@ begin
inc(lvl) inc(lvl)
else if ( sfaOutlineMergeParent in TmpNode.FoldAction) then else if ( sfaOutlineMergeParent in TmpNode.FoldAction) then
dec(lvl); dec(lvl);
//if (FLastNode.LineIndex >= 0) if (FLastNode.LineIndex >= 0)
//and (sfaOutlineKeepLevelOnSameLine in FLastNode.FoldAction) and (sfaOutlineKeepLevel in FLastNode.FoldAction)
//and (FLastNode.LineIndex < TmpNode.LineIndex) then and (FLastNode.LineIndex < TmpNode.LineIndex) then
// inc(lvl); inc(lvl);
AddHighlight(TmpNode); AddHighlight(TmpNode);
{$IFDEF SynEditMarkupFoldColoringDebug}
//with FFoldColorInfos[FFoldColorInfosCount - 1] do
// DebugLn(' %d-%d', [x, x2]);
{$ENDIF}
//if (FFoldColorInfosCount - 1 > 0) if (FFoldColorInfosCount - 1 > 0)
//and (FFoldColorInfos[FFoldColorInfosCount - 1].X = FFoldColorInfos[FFoldColorInfosCount - 2].X) then and (FFoldColorInfos[FFoldColorInfosCount - 1].X = FFoldColorInfos[FFoldColorInfosCount - 2].X) then
//begin begin
// // if child is on same x-pos keep level // if child is on same x-pos keep level
// if (sfaClose in FFoldColorInfos[FFoldColorInfosCount - 1].SrcNode.FoldAction) if (sfaClose in FFoldColorInfos[FFoldColorInfosCount - 1].SrcNode.FoldAction)
// or (sfaOutlineMergeLevelOnWrongCol in FFoldColorInfos[FFoldColorInfosCount - 1].SrcNode.FoldAction) then begin or (sfaOutlineKeepLevel in FFoldColorInfos[FFoldColorInfosCount - 2].SrcNode.FoldAction) then begin
// lvl := FFoldColorInfos[FFoldColorInfosCount - 2].Level; lvl := FFoldColorInfos[FFoldColorInfosCount - 2].Level;
// FFoldColorInfos[FFoldColorInfosCount - 1].Level := lvl; FFoldColorInfos[FFoldColorInfosCount - 1].Level := lvl;
// FFoldColorInfos[FFoldColorInfosCount - 1].ColorIdx := Max(0, lvl) mod (length(Colors)); FFoldColorInfos[FFoldColorInfosCount - 1].ColorIdx := Max(0, lvl) mod (length(Colors));
// end; end;
//end; end;
if not (sfaOutlineKeepLevel in TmpNode.FoldAction) if not (sfaOutlineKeepLevel in TmpNode.FoldAction)
{and not (sfaOutlineKeepLevelOnSameLine in TmpNode.FoldAction)} then {and not (sfaOutlineKeepLevelOnSameLine in TmpNode.FoldAction)} then
@ -551,10 +548,6 @@ begin
end; end;
if Found then begin if Found then begin
AddHighlight(TmpNode); AddHighlight(TmpNode);
{$IFDEF SynEditMarkupFoldColoringDebug}
//with FFoldColorInfos[FFoldColorInfosCount - 1] do
// DebugLn(' %d-%d', [x, x2]);
{$ENDIF}
with FFoldColorInfos[FFoldColorInfosCount - 1] do begin with FFoldColorInfos[FFoldColorInfosCount - 1] do begin
LevelBefore := lvlB; LevelBefore := lvlB;
LevelAfter := lvlA; LevelAfter := lvlA;