Skip to content

Commit

Permalink
POC for non-distracting folding for sections. I know it shouldn't dir…
Browse files Browse the repository at this point in the history
…ectly call TInnoSetupStyler from ScintEdit, just like this for the POC.
  • Loading branch information
martijnlaan committed Jun 15, 2024
1 parent 47f3b71 commit 68a0c3a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function ScintRawStringIsBlank(const S: TScintRawString): Boolean;
implementation

uses
ShellAPI, RTLConsts, UITypes, GraphUtil;
ShellAPI, RTLConsts, UITypes, GraphUtil, ScintStylerInnoSetup;

function ScintRawStringIsBlank(const S: TScintRawString): Boolean;
begin
Expand Down Expand Up @@ -1794,10 +1794,28 @@ procedure TScintEdit.StyleNeeded(const EndPos: Integer);
FStyler.FText := '';
end;

{ Add fold headers at section tags. These appear with section scNone with the
next line not being section sNone. }

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);
{ 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);
end;
end else
Call(SCI_SETFOLDLEVEL, I, SC_FOLDLEVELBASE);
end;

Result := LastLine;
Expand Down
2 changes: 2 additions & 0 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3852,6 +3852,8 @@ procedure TCompileForm.MoveCaretAndActivateMemo(AMemo: TCompScintEdit; const Lin
else
Pos := AMemo.CaretPosition; { Not actually moving caret - it's already were we want it}

AMemo.Call(SCI_ENSUREVISIBLE, AMemo.GetLineFromPosition(Pos), 0);

{ If the line isn't in view, scroll so that it's in the center }
if not AMemo.IsPositionInViewVertically(Pos) then
AMemo.TopLine := AMemo.GetVisibleLineFromDocLine(AMemo.GetLineFromPosition(Pos)) -
Expand Down
15 changes: 15 additions & 0 deletions Projects/Src/CompScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ procedure TCompScintEdit.CreateWnd;
Call(SCI_SETMARGINMASKN, 2, not (SC_MASK_FOLDERS or mmIconsMask));
Call(SCI_SETMARGINCURSORN, 2, SC_CURSORARROW);

Call(SCI_SETMARGINTYPEN, 3, SC_MARGIN_SYMBOL);
Call(SCI_SETMARGINMASKN, 3, LPARAM(SC_MASK_FOLDERS));
Call(SCI_SETMARGINCURSORN, 3, SC_CURSORARROW);
Call(SCI_SETMARGINWIDTHN, 3, 16);
Call(SCI_SETMARGINSENSITIVEN, 3, 1);
Call(SCI_SETAUTOMATICFOLD, SC_AUTOMATICFOLD_SHOW or SC_AUTOMATICFOLD_CLICK or SC_AUTOMATICFOLD_CHANGE, 0);

Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_ARROWDOWN);
Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_ARROW);
Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
Call(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);

Call(SCI_MARKERDEFINE, mmLineError, SC_MARK_BACKFORE);
Call(SCI_MARKERSETFORE, mmLineError, clWhite);
Call(SCI_MARKERSETBACK, mmLineError, clMaroon);
Expand Down

0 comments on commit 68a0c3a

Please sign in to comment.