SynEdit: fixed TSynSizedDifferentialAVLTree.FindNodeAtPosition, left-side-count-sum was wrong. Fixed AdjustForLinesDeleted.

git-svn-id: trunk@62607 -
This commit is contained in:
martin 2020-02-03 20:23:59 +00:00
parent 0fbdea80f8
commit 10729ff5a2

View File

@ -3029,11 +3029,13 @@ begin
else else
if APosition = aStartPosition then begin if APosition = aStartPosition then begin
aSizesBeforeSum := aSizesBeforeSum + Result.FLeftSizeSum;
break; break;
end end
else else
if aStartPosition < APosition then begin if aStartPosition < APosition then begin
aSizesBeforeSum := aSizesBeforeSum + Result.FLeftSizeSum;
if (Result.FRight = nil) then begin if (Result.FRight = nil) then begin
case AMode of case AMode of
afmCreate: Result := CreateRight(Result, aStartPosition); afmCreate: Result := CreateRight(Result, aStartPosition);
@ -3044,7 +3046,7 @@ begin
break; break;
end; end;
Store(0, Result); // Precessor Store(0, Result); // Precessor
aSizesBeforeSum := aSizesBeforeSum + Result.FLeftSizeSum + Result.FSize; aSizesBeforeSum := aSizesBeforeSum + Result.FSize;
Result := Result.FRight; Result := Result.FRight;
end; end;
end; // while end; // while
@ -3078,20 +3080,26 @@ end;
procedure TSynSizedDifferentialAVLTree.AdjustForLinesDeleted(AStartLine, ALineCount: Integer); procedure TSynSizedDifferentialAVLTree.AdjustForLinesDeleted(AStartLine, ALineCount: Integer);
var var
Current : TSynSizedDifferentialAVLNode; Current : TSynSizedDifferentialAVLNode;
CurrentLine, LastLineToDelete: Integer; CurrentLine: Integer;
begin begin
Current := TSynSizedDifferentialAVLNode(fRoot); Current := TSynSizedDifferentialAVLNode(fRoot);
CurrentLine := FRootOffset;; CurrentLine := FRootOffset;;
LastLineToDelete := AStartLine + ALineCount - 1; // only valid for delete; ALineCount < 0 // LastLineToDelete := AStartLine + ALineCount - 1; // only valid for delete; ALineCount < 0
while (Current <> nil) do begin while (Current <> nil) do begin
CurrentLine := CurrentLine + Current.FPositionOffset; CurrentLine := CurrentLine + Current.FPositionOffset;
if (AStartLine = CurrentLine) or if (AStartLine = CurrentLine) then begin
((AStartLine < CurrentLine) and (LastLineToDelete >= CurrentLine)) then begin Current := Current.FRight;
{ $IFDEF AssertSynMemIndex} if Current = nil then
raise Exception.Create('TSynEditMarkLineList.AdjustForLinesDeleted node to remove'); break;
{ $ENDIF} assert((Current.FPositionOffset > ALineCount), 'TSynSizedDifferentialAVLTree.AdjustForLinesDeleted: (Current=nil) or (Current.FPositionOffset > ALineCount)');
Current.FPositionOffset := Current.FPositionOffset - ALineCount;
break;
// ((AStartLine < CurrentLine) and (LastLineToDelete >= CurrentLine)) then begin
//{ $IFDEF AssertSynMemIndex}
//raise Exception.Create('TSynEditMarkLineList.AdjustForLinesDeleted node to remove');
//{ $ENDIF}
end end
else if AStartLine < CurrentLine then begin else if AStartLine < CurrentLine then begin