Skip to content

Commit

Permalink
Fixed issue JAM-Software#487: When OnAddToSelection is called, GetFir…
Browse files Browse the repository at this point in the history
…stSelected returns nil

# Conflicts:
#	Source/VirtualTrees.pas
  • Loading branch information
Joachim Marder authored and ValtsS committed Jan 24, 2019
1 parent 4edece2 commit e0139e9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Source/VirtualTrees.pas
Original file line number Diff line number Diff line change
Expand Up @@ -24264,8 +24264,9 @@ function TBaseVirtualTree.InternalAddToSelection(const NewItems: TNodeArray; New
CurrentEnd: Integer;
Constrained,
SiblingConstrained: Boolean;

lPreviousSelectedCount: Integer;
begin
lPreviousSelectedCount := FSelectionCount;
// The idea behind this code is to use a kind of reverse merge sort. QuickSort is quite fast
// and would do the job here too but has a serious problem with already sorted lists like FSelection.

Expand All @@ -24275,6 +24276,7 @@ function TBaseVirtualTree.InternalAddToSelection(const NewItems: TNodeArray; New
for I := 0 to NewLength - 1 do
begin
Include(NewItems[I].States, vsSelected);
Inc(FSelectionCount);
if Assigned(FOnAddToSelection) then
FOnAddToSelection(Self, NewItems[I]);
end;
Expand All @@ -24296,7 +24298,8 @@ function TBaseVirtualTree.InternalAddToSelection(const NewItems: TNodeArray; New
else
begin
Include(NewItems[I].States, vsSelected);
if Assigned(FOnAddToSelection) then
Inc(FSelectionCount);
if Assigned(FOnAddToSelection) then
FOnAddToSelection(Self, NewItems[I]);
end;
end;
Expand All @@ -24312,12 +24315,12 @@ function TBaseVirtualTree.InternalAddToSelection(const NewItems: TNodeArray; New
if NewLength > 1 then
QuickSort(NewItems, 0, NewLength - 1);
// 3) Make room in FSelection for the new items.
if FSelectionCount + NewLength >= Length(FSelection) then
SetLength(FSelection, FSelectionCount + NewLength);
if lPreviousSelectedCount + NewLength >= Length(FSelection) then
SetLength(FSelection, lPreviousSelectedCount + NewLength);

// 4) Merge in new items
J := NewLength - 1;
CurrentEnd := FSelectionCount - 1;
CurrentEnd := lPreviousSelectedCount - 1;

while J >= 0 do
begin
Expand Down Expand Up @@ -24353,7 +24356,7 @@ function TBaseVirtualTree.InternalAddToSelection(const NewItems: TNodeArray; New
CurrentEnd := I;
end;

Inc(FSelectionCount, NewLength);
Assert(FSelectionCount = (lPreviousSelectedCount + NewLength), 'Fixing issue #487 seems to ahve caused a problem here.')
end;
end;

Expand Down

0 comments on commit e0139e9

Please sign in to comment.