Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Jun 16, 2024
1 parent 670d078 commit 894af3b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ TScintCustomStyler = class(TComponent)
function ConsumeString(const Chars: TScintRawCharSet): TScintRawString;
function CurCharIn(const Chars: TScintRawCharSet): Boolean;
function CurCharIs(const C: AnsiChar): Boolean;
procedure GetFoldLevel(const LineState: TScintLineState; var Level: Integer;
var Header: Boolean); virtual; abstract;
procedure GetStyleAttributes(const Style: Integer;
var Attributes: TScintStyleAttributes); virtual; abstract;
function LineTextSpans(const S: TScintRawString): Boolean; virtual;
Expand Down Expand Up @@ -1815,32 +1817,21 @@ procedure TScintEdit.StyleNeeded(const EndPos: Integer);
FStyler.FText := '';
end;

{ Set line states and also add fold headers when not in a section. }
var FoldLevel: Integer;
var FoldHeader: Boolean;
FStyler.GetFoldLevel(FStyler.FLineState, FoldLevel, FoldHeader);
var FoldFlags := 0;
if FoldHeader then
FoldFlags := FoldFlags or SC_FOLDLEVELHEADERFLAG;
FoldLevel := (SC_FOLDLEVELBASE+FoldLevel) or FoldFlags;

for var I := FirstLine to LastLine do begin
var OldState := FLines.GetState(I);
if FStyler.FLineState <> OldState then
Call(SCI_SETLINESTATE, I, FStyler.FLineState);

var Section := TInnoSetupStyler.GetSectionFromLineState(FStyler.LineState);
if Section <> scNone then
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE+1)
else begin
{ Everything outside a section should have the header flag, even if it's
just a blank line or a comment. Doing this doesn't cause many fold
markers: if two lines have the same level and header flag the first
line doesn't get a fold mark since there's nothing to expand.
Not doing this however is a problem: for example, if the first
line is empty and and the second line starts a section then those two
lines would logically considered to be in the same 'fold' and edits
on the first line would affect the section if collapsed.
Did notice an issue (Scintilla bug?): Add a section with some lines.
Collapse it. Break the section header for example by removing ']'.
Scintialla now auto expands the section and removes the fold mark.
Retype the ']'. Scintilla now displays the old fold mark to expand the
section but it's already expanded. }
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE or SC_FOLDLEVELHEADERFLAG);
end;
var OldLevel := Call(SCI_GETFOLDLEVEL, I, 0);
if FoldLevel <> OldLevel then
Call(SCI_SETFOLDLEVEL, I, FoldLevel);
end;

Result := LastLine;
Expand Down
28 changes: 28 additions & 0 deletions Components/ScintStylerInnoSetup.pas
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ TInnoSetupStyler = class(TScintCustomStyler)
procedure SetISPPInstalled(const Value: Boolean);
protected
procedure CommitStyle(const Style: TInnoSetupStylerStyle);
procedure GetFoldLevel(const LineState: TScintLineState; var Level: Integer;
var Header: Boolean); override;
procedure GetStyleAttributes(const Style: Integer;
var Attributes: TScintStyleAttributes); override;
function LineTextSpans(const S: TScintRawString): Boolean; override;
Expand Down Expand Up @@ -934,6 +936,32 @@ function TInnoSetupStyler.GetFlagsWordList(Section: TInnoSetupStylerSection): An
Result := FFlagsWordList[Section];
end;

procedure TInnoSetupStyler.GetFoldLevel(const LineState: TScintLineState;
var Level: Integer; var Header: Boolean);
begin
var Section := TInnoSetupStyler.GetSectionFromLineState(LineState);
if Section <> scNone then begin
Level := 1;
Header := False;
end else begin
{ Everything outside a section should have the header flag, even if it's just
a blank line or a comment. Doing this doesn't cause many fold markers: if
two lines have the same level and header flag the first line doesn't get a
fold mark since there's nothing to expand. Not doing this however is a
problem: for example, if the first line is empty and and the second line
starts a section then those two lines would logically considered to be in
the same 'fold' and edits on the first line would affect the section if
collapsed.
Did notice an issue (Scintilla bug?): Add a section with some lines.
Collapse it. Break the section header for example by removing ']'.
Scintialla now auto expands the section and removes the fold mark.
Retype the ']'. Scintilla now displays the old fold mark to expand the
section but it's already expanded. }
Level := 0;
Header := True;
end;
end;

function TInnoSetupStyler.GetKeywordsWordList(Section: TInnoSetupStylerSection): AnsiString;
begin
Result := FKeywordsWordList[Section];
Expand Down

0 comments on commit 894af3b

Please sign in to comment.