vToBeDeleted := Self.InternalRange(vBeginning, vEnd); { optimized cases: adjacent to the gap. } {$IFDEF OPT} if (vToBeDeleted[0].End1 = fGapStart) and (vToBeDeleted[0].End1 > vToBeDeleted[0].Beginning) { TODO and some gap size limit is not exceeded } then begin fGapStart := vToBeDeleted[0].Beginning; assert(fGapStart = vBeginning); FillChar(fBuffer[fGapStart], vToBeDeleted[0].End1 - fGapStart, 0); { for better debugging. } vToBeDeleted[0].End1 := fGapStart; end; if (vToBeDeleted[1].Beginning = fGapEnd) and (vToBeDeleted[1].End1 > vToBeDeleted[1].Beginning) { TODO and some gap size limit is not exceeded } then begin fGapEnd := vToBeDeleted[1].End1; assert(fGapEnd = vEnd); FillChar(fBuffer[vToBeDeleted[1].Beginning], fGapEnd - vToBeDeleted[1].Beginning, 0); { for better debugging. } vToBeDeleted[1].Beginning := fGapEnd; end; {$ENDIF} { normal case: need to move data around. } vFrontier := Self.PositionFromTextMark(fEnd1); vEnd := Self.PositionFromTextMark(aPosition, aCount); // where the block to be deleted ends. vSource := Self.InternalRange(vEnd, vFrontier); vToBeDeleted := Self.InternalRange(vBeginning, vFrontier); // as copy destination, use _everything_ until the end. // vSource -> vToBeDeleted. // tail -> move to vEnd (beginning of vSource). Dump(Format('Copy %d', [fEnd1.Position - (aPosition.Position + aCount)])); Self.Copy(vSource, vToBeDeleted, fEnd1.Position - (aPosition.Position + aCount));