mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 17:00:17 +02:00
SynEdit: fix save/load fold-state.
This commit is contained in:
parent
b6866311bb
commit
339ede7382
@ -1452,7 +1452,6 @@ var
|
||||
begin
|
||||
// reset counters for following <FoldList>
|
||||
CntSum := 0;
|
||||
LinesSum := 0;
|
||||
|
||||
HideBit := 0;;
|
||||
case LastFoldType of
|
||||
@ -1473,7 +1472,7 @@ var
|
||||
exit;
|
||||
l1 := FWriteCache[AStartIndex].aY;
|
||||
if (ACount > SEQMaxNodeCount) or
|
||||
(ALines > SEQMaxNodeCount) or
|
||||
(ALines > SEQMaxNodeCount) or // TODO should this be SEQMaxLineDistEach ?
|
||||
(l1 - l2 > SEQMaxLineDistEach) or
|
||||
(l1 - FirstLine > SEQMaxLineDistTotal)
|
||||
then
|
||||
@ -1538,6 +1537,7 @@ begin
|
||||
end;
|
||||
i := 0;
|
||||
while i < FWriteCacheLen do begin
|
||||
LinesSum := 0;
|
||||
WriteCachedNode(i);
|
||||
|
||||
DeferredZero := False; // special case at start, there may be 0 more folded nodes
|
||||
@ -1729,7 +1729,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
dec(FReadCount);
|
||||
inc(FReadSumLen, aLen);
|
||||
if FReadType <> scftOpen then
|
||||
inc(FReadSumLen, aLen);
|
||||
Result := FReadType;
|
||||
end;
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<Item Name="O0t">
|
||||
<Item Name="O0 NO-gt1">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
@ -77,7 +77,7 @@
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<Item Name="O0tt">
|
||||
<Item Name="O0riota1 NO-gt">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
@ -109,7 +109,7 @@
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<Item Name="O0ttt">
|
||||
<Item Name="O0 -gt">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
@ -141,7 +141,71 @@
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<Item Name="O0tttt">
|
||||
<Item Name="O0 -gtt">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="units\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<CPPInline Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<Checks>
|
||||
<RangeChecks Value="True"/>
|
||||
<OverflowChecks Value="True"/>
|
||||
<StackChecks Value="True"/>
|
||||
</Checks>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
<UseHeaptrc Value="True"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-gt
|
||||
-dWithSynBiDi"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<Item Name="O0 -gttt">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="units\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<CPPInline Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<Checks>
|
||||
<RangeChecks Value="True"/>
|
||||
<OverflowChecks Value="True"/>
|
||||
<StackChecks Value="True"/>
|
||||
</Checks>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
<UseHeaptrc Value="True"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-gt
|
||||
-dWithSynBiDi"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<Item Name="O0 -gtttt <nil>">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
@ -429,21 +493,55 @@
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<SharedMatrixOptions Count="14">
|
||||
<Item1 ID="394047217475" Targets="SynEdit" Modes="O0riota,O0t,O0tt,O0ttt,O0tttt,O1riota,O2riota,O3riota,O4riota" Value="-CR"/>
|
||||
<Item2 ID="832332610162" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota,O0t,O0tt,O0ttt,O0tttt,O1riota,O2riota,O3riota,O4riota" Value="-dSynCheckPaintLock -dSynClipboardExceptions -dAssertSynMemIndex -dSynAssert -dSynAssertFold"/>
|
||||
<Item3 ID="476451423372" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0,O0riota,O0t,O0tt,O0ttt,O0tttt" Value="-O-"/>
|
||||
<Item4 ID="353669118028" Targets="#project,SynEdit,LCL,LazUtils" Modes="O1,O1riota" Value="-O-1"/>
|
||||
<Item Name="O1 - SynFoldDebug SynFoldSaveDebug">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="units\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<CPPInline Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<Checks>
|
||||
<RangeChecks Value="True"/>
|
||||
<OverflowChecks Value="True"/>
|
||||
<StackChecks Value="True"/>
|
||||
</Checks>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
<UseHeaptrc Value="True"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-gt
|
||||
-dWithSynBiDi"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
<SharedMatrixOptions Count="16">
|
||||
<Item1 ID="394047217475" Targets="SynEdit" Modes="O0riota,O1riota,O2riota,O3riota,O4riota" Value="-CR"/>
|
||||
<Item2 ID="832332610162" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota,O1riota,O2riota,O3riota,O4riota,O1 - SynFoldDebug SynFoldSaveDebug,O0riota1 NO-gt,O0 -gt,O0 -gtt,O0 -gttt,O0 -gtttt <nil>" Value="-dSynCheckPaintLock -dSynClipboardExceptions -dAssertSynMemIndex -dSynAssert -dSynAssertFold"/>
|
||||
<Item3 ID="476451423372" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0,O0riota,O0riota1 NO-gt,O0 -gt,O0 -gtt,O0 -gttt,O0 -gtttt <nil>,O0 NO-gt1" Value="-O-"/>
|
||||
<Item4 ID="353669118028" Targets="#project,SynEdit,LCL,LazUtils" Modes="O1,O1riota,O1 - SynFoldDebug SynFoldSaveDebug" Value="-O-1"/>
|
||||
<Item5 ID="705666282637" Targets="#project,SynEdit,LCL,LazUtils" Modes="O2,O2riota" Value="-O-2"/>
|
||||
<Item6 ID="139516671950" Targets="#project,SynEdit,LCL,LazUtils" Modes="O3,O3riota" Value="-O-3"/>
|
||||
<Item7 ID="951152446553" Targets="#project,SynEdit,LCL,LazUtils" Modes="O4,O4riota" Value="-O-4"/>
|
||||
<Item8 ID="290834599239" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota,O0t,O0tt,O0ttt,O0tttt,O1riota,O2riota,O3riota,O4riota" Value="-Criot"/>
|
||||
<Item8 ID="290834599239" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota,O1riota,O2riota,O3riota,O4riota,O1 - SynFoldDebug SynFoldSaveDebug,O0 -gtttt <nil>,O0 -gttt,O0 -gtt,O0 -gt,O0riota1 NO-gt" Value="-Criot"/>
|
||||
<Item9 ID="862413201644" Targets="#project,SynEdit,LCL,LazUtils" Value="-CR"/>
|
||||
<Item10 ID="552061010909" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota,O0t,O0tt,O0ttt,O0tttt,O1riota,O2riota,O3riota,O4riota" Value="-Sa"/>
|
||||
<Item11 ID="362454399046" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0t" Value="-Ct"/>
|
||||
<Item12 ID="710122956011" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0tt" Value="-Ctt"/>
|
||||
<Item13 ID="041078026067" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0ttt" Value="-Cttt"/>
|
||||
<Item14 ID="961200635277" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0tttt" Value="-Ctttt"/>
|
||||
<Item10 ID="552061010909" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota,O1riota,O2riota,O3riota,O4riota,O1 - SynFoldDebug SynFoldSaveDebug,O0riota1 NO-gt,O0 -gt,O0 -gtt,O0 -gttt,O0 -gtttt <nil>" Value="-Sa"/>
|
||||
<Item11 ID="362454399046" Targets="#project,SynEdit,LCL,LazUtils" Modes="O1 - SynFoldDebug SynFoldSaveDebug,O0 -gt" Value="-gt- -gt"/>
|
||||
<Item12 ID="710122956011" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0 -gtt" Value="-gt- -gtt"/>
|
||||
<Item13 ID="041078026067" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0 -gttt" Value="-gt- -gttt"/>
|
||||
<Item14 ID="961200635277" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0 -gtttt <nil>" Value="-gt- -gtttt"/>
|
||||
<Item15 ID="901082361902" Targets="#project,SynEdit,LCL,LazUtils" Modes="O0riota1 NO-gt,O0 NO-gt1,O4,O3,O2,O1" Value="-gt-"/>
|
||||
<Item16 ID="058689630976" Targets="#project,SynEdit,LCL,LazUtils" Modes="O1 - SynFoldDebug SynFoldSaveDebug" Value="-dSynFoldDebug -dSynFoldSaveDebug"/>
|
||||
</SharedMatrixOptions>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
|
@ -56,6 +56,12 @@ type
|
||||
function TestTextHide4: TStringArray;
|
||||
function TestTextPlain: TStringArray;
|
||||
function TestTextBug21473: TStringArray;
|
||||
(* TestTextNodeDesc_FoldOpenFold_WithDistance
|
||||
Encode repeated runs of: fold, not-fold, fold
|
||||
With LineOffs > SEQMax** to force a 2nd "repeat-run" (and a " p<sum>" inbetween)
|
||||
// Currently, if <sum> is wrong the current "repeat-run" is kept, but the next aborted.
|
||||
*)
|
||||
function TestTextNodeDesc_FoldOpenFold_WithDistance: TStringArray;
|
||||
protected
|
||||
procedure TstSetText(AName: String; AText: Array of String);
|
||||
procedure TstFold(AName: String; AFoldAtIndex: integer; AExpectedLines: Array of Integer);
|
||||
@ -88,6 +94,7 @@ type
|
||||
procedure TestFold;
|
||||
procedure TestFoldEdit;
|
||||
procedure TestFoldStateFromText;
|
||||
procedure TestFoldStateFromText_2;
|
||||
procedure TestFoldStateDesc;
|
||||
procedure TestFoldProvider;
|
||||
procedure TestNestedFoldsList;
|
||||
@ -681,6 +688,52 @@ begin
|
||||
Result[34] := '';
|
||||
end;
|
||||
|
||||
function TTestFoldedView.TestTextNodeDesc_FoldOpenFold_WithDistance: TStringArray;
|
||||
begin
|
||||
SetLength(Result, 6000);
|
||||
Result[ 0] := 'unit a';
|
||||
Result[ 1] := 'interface';
|
||||
Result[ 2] := 'implementation';
|
||||
Result[ 3] := '';
|
||||
Result[ 4] := 'procedure Foo0;';
|
||||
Result[ 5] := 'begin';
|
||||
Result[ 6] := ' //';
|
||||
Result[ 7] := 'end';
|
||||
Result[ 8] := '';
|
||||
Result[ 9] := 'procedure Foo1;';
|
||||
Result[ 10] := '';
|
||||
Result[ 11] := ' procedure Foo1Inner1;';
|
||||
Result[ 12] := ' begin';
|
||||
Result[ 13] := ' end;';
|
||||
Result[ 14] := '';
|
||||
Result[ 15] := ' procedure Foo1Inner2;';
|
||||
Result[ 16] := ' begin';
|
||||
Result[ 17] := ' //;';
|
||||
Result[ 18] := ' end;';
|
||||
Result[ 19] := '';
|
||||
Result[ 20] := 'begin';
|
||||
Result[ 21] := ' //';
|
||||
Result[ 22] := 'end;';
|
||||
Result[ 23] := '';
|
||||
Result[ 24] := '';
|
||||
Result[ 25] := 'procedure Foo2;';
|
||||
Result[ 26] := 'begin';
|
||||
Result[ 27] := ' //';
|
||||
Result[ 28] := 'end';
|
||||
Result[ 29] := '';
|
||||
Result[ 30] := 'procedure Foo3;';
|
||||
Result[ 31] := 'begin';
|
||||
Result[ 32] := ' //';
|
||||
// Make this really long
|
||||
Result[5983] := 'end';
|
||||
Result[5984] := '';
|
||||
Result[5985] := 'procedure Foo4;';
|
||||
Result[5986] := 'begin';
|
||||
Result[5987] := ' //';
|
||||
Result[5988] := 'end';
|
||||
Result[5989] := '';
|
||||
|
||||
end;
|
||||
|
||||
procedure TTestFoldedView.TestFold;
|
||||
procedure RunTest;
|
||||
@ -1661,6 +1714,103 @@ begin
|
||||
AssertEquals(FoldedView.ViewedCount, 4999-2);
|
||||
end;
|
||||
|
||||
procedure TTestFoldedView.TestFoldStateFromText_2;
|
||||
var
|
||||
WithBeginEndEnabled, WithBeginFooZeroFolded,
|
||||
WithBeginFooInnerOneFolded, WithUnfoldAll, WithFixAfterFolding: Boolean;
|
||||
FoldInfoAsString: String;
|
||||
|
||||
procedure NewSyn;
|
||||
begin
|
||||
ReCreateEdit;
|
||||
SetLines(TestTextNodeDesc_FoldOpenFold_WithDistance);
|
||||
|
||||
if WithBeginEndEnabled then
|
||||
EnableFolds( [cfbtBeginEnd..cfbtNone], [], [cfbtBeginEnd..cfbtNone] - [cfbtTopBeginEnd, cfbtProcedure])
|
||||
else
|
||||
EnableFolds( [cfbtBeginEnd..cfbtNone], [], [cfbtBeginEnd..cfbtNone] - [cfbtProcedure]);
|
||||
end;
|
||||
|
||||
procedure TestIsFolded(AIndex: Integer; AColIdx: Integer = 0);
|
||||
begin
|
||||
if not FoldedView.IsFoldedAtTextIndex(AIndex, AColIdx) then
|
||||
TestFail('is folded', IntToStr(AIndex), 'Folded', 'Not folded');
|
||||
end;
|
||||
procedure TestIsUnfolded(AIndex: Integer; AColIdx: Integer = 0);
|
||||
begin
|
||||
if FoldedView.IsFoldedAtTextIndex(AIndex, AColIdx) then
|
||||
TestFail('not folded', IntToStr(AIndex), 'Folded', 'Not folded');
|
||||
end;
|
||||
procedure TestFolded(ExpFolded: Boolean; AIndex: Integer; AColIdx: Integer = 0);
|
||||
begin
|
||||
if ExpFolded then
|
||||
TestIsFolded(AIndex, AColIdx)
|
||||
else
|
||||
TestIsUnfolded(AIndex, AColIdx);
|
||||
end;
|
||||
|
||||
begin
|
||||
for WithBeginEndEnabled := low(Boolean) to high(Boolean) do
|
||||
for WithBeginFooZeroFolded := low(Boolean) to high(Boolean) do
|
||||
for WithBeginFooInnerOneFolded := low(Boolean) to high(Boolean) do
|
||||
for WithUnfoldAll := low(Boolean) to high(Boolean) do
|
||||
for WithFixAfterFolding := low(Boolean) to high(Boolean) do
|
||||
begin
|
||||
NewSyn;
|
||||
|
||||
// The first run will have a repeated fold / rather than "len=0" (see "DeferredZero")
|
||||
if WithBeginFooZeroFolded then
|
||||
FoldedView.FoldAtTextIndex(4); // Foo0
|
||||
FoldedView.FoldAtTextIndex( 9); // Foo1
|
||||
if WithBeginFooInnerOneFolded then
|
||||
FoldedView.FoldAtTextIndex( 11); // FooInner1
|
||||
FoldedView.FoldAtTextIndex( 25); // Foo2
|
||||
FoldedView.FoldAtTextIndex( 30); // Foo3
|
||||
FoldedView.FoldAtTextIndex(5985); // Foo4
|
||||
|
||||
FoldInfoAsString := SynEdit.FoldState;
|
||||
|
||||
if WithFixAfterFolding then begin
|
||||
FoldedView.FixFoldingAtTextIndex(0, SynEdit.Lines.Count-1);
|
||||
TestCompareString('after FixFolding', FoldInfoAsString, SynEdit.FoldState);
|
||||
end;
|
||||
//tmp := FoldedView.GetFoldDescription(0, 1, -1, -1, False, False);
|
||||
|
||||
if WithUnfoldAll then
|
||||
SynEdit.UnfoldAll
|
||||
else
|
||||
NewSyn;
|
||||
|
||||
SynEdit.FoldState := FoldInfoAsString;
|
||||
|
||||
TestIsUnfolded( 0);
|
||||
TestIsUnfolded( 1);
|
||||
TestIsUnfolded( 2);
|
||||
TestIsUnfolded( 3);
|
||||
TestFolded(WithBeginFooZeroFolded, 4); // Foo0
|
||||
TestIsUnfolded( 5);
|
||||
|
||||
TestIsUnfolded( 8);
|
||||
TestIsFolded ( 9); // Foo1
|
||||
TestIsUnfolded(10);
|
||||
|
||||
TestFolded(WithBeginFooInnerOneFolded, 11); // Foo0
|
||||
TestIsUnfolded(12);
|
||||
|
||||
TestIsUnfolded(24);
|
||||
TestIsFolded (25); // Foo2
|
||||
TestIsUnfolded(26);
|
||||
|
||||
TestIsUnfolded(29);
|
||||
TestIsFolded (30); // Foo3
|
||||
TestIsUnfolded(31);
|
||||
|
||||
TestIsUnfolded(5984);
|
||||
TestIsFolded (5985); // Foo4
|
||||
TestIsUnfolded(5986);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestFoldedView.TestFoldStateDesc;
|
||||
var
|
||||
a1,a2{, a3, a4}: String;
|
||||
|
Loading…
Reference in New Issue
Block a user