1419
1420
private shrinkNode(node: TreeNode, start: BufferCursor, end: BufferCursor) {
1422
>
const originalStartPos = piece.start;
1423
>
const originalEndPos = piece.end;
1424
>
1425
>
// old piece, originalStartPos, start
1426
>
const oldLength = piece.length;
1427
>
const oldLFCnt = piece.lineFeedCnt;
1428
>
const newEnd = start;
1429
>
const newLineFeedCnt = this.getLineFeedCnt(piece.bufferIndex, piece.start, newEnd);
1430
>
const newLength = this.offsetInBuffer(piece.bufferIndex, start) - this.offsetInBuffer(piece.bufferIndex, originalStartPos);
1431
>
1432
>
node.piece = new Piece(
1433
>
piece.bufferIndex,
1434
>
piece.start,
1435
>
newEnd,
1436
>
newLineFeedCnt,
1437
>
newLength
1438
>
);
1439
>
1440
>
updateTreeMetadata(this, node, newLength - oldLength, newLineFeedCnt - oldLFCnt);
1441
>
1442
>
// new right piece, end, originalEndPos
1443
>
const newPiece = new Piece(
1444
>
piece.bufferIndex,
1445
>
end,
1446
>
originalEndPos,
1447
>
this.getLineFeedCnt(piece.bufferIndex, end, originalEndPos),
1448
>
this.offsetInBuffer(piece.bufferIndex, originalEndPos) - this.offsetInBuffer(piece.bufferIndex, end)
1449
>
);
1450
>
1451
>
const newNode = this.rbInsertRight(node, newPiece);
1452
>
this.validateCRLFWithPrevNode(newNode);
1453
>
}
1454
1455
private appendToNode(node: TreeNode, value: string): void {