Skip to content

Commit

Permalink
Simplify to make it work better on edits. This way Scintilla doesnt e…
Browse files Browse the repository at this point in the history
…xpand sections when editing above them and also it doesnt remove whitespace lines at the end of a collapsed section when the section tag is removed (like by deleting ]). 😏
  • Loading branch information
martijnlaan committed Jun 16, 2024
1 parent 1d33c96 commit 439624b
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1812,38 +1812,21 @@ procedure TScintEdit.StyleNeeded(const EndPos: Integer);
Call(SCI_SETSTYLINGEX, Length(FStyler.FStyleStr), LPARAM(PAnsiChar(FStyler.FStyleStr)));

FStyler.FStyleStr := '';
FStyler.FText := '';
end;

{ Set line states and also add fold headers at section tags. These appear
with section scNone with the next line not being section sNone. }

var ExtraFlags := 0;
if FStyler.FText = '' then begin
{ All spanned lines are empty. If only some lines are empty we miss this. }
ExtraFlags := ExtraFlags or SC_FOLDLEVELWHITEFLAG;
end;

FStyler.FText := '';
{ Set line states and also add fold headers when not in a section. }

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 begin
{ We're in a section, make this line as level 1 }
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE+1 or ExtraFlags);
{ Also look at previous line to see if was the section tag, and if so
retroactively set it as a folder header }
if I > 0 then begin
var PrevState := FLines.GetState(I-1);
var PrevSection := TInnoSetupStyler.GetSectionFromLineState(PrevState);
if PrevSection = scNone then
Call(SCI_SETFOLDLEVEL, I-1, SC_FOLDLEVELBASE or SC_FOLDLEVELHEADERFLAG or ExtraFlags);
end;
end else
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE or ExtraFlags);
if Section <> scNone then
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE+1)
else
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE or SC_FOLDLEVELHEADERFLAG);
end;

Result := LastLine;
Expand Down

0 comments on commit 439624b

Please sign in to comment.