1682
1683
private fixCRLF(prev: TreeNode, next: TreeNode) {
1685
>
// update node
1686
>
const lineStarts = this._buffers[prev.piece.bufferIndex].lineStarts;
1687
>
let newEnd: BufferCursor;
1688
>
if (prev.piece.end.column === 0) {
1689
// it means, last line ends with \r, not \r\n
1690
newEnd = { line: prev.piece.end.line - 1, column: lineStarts[prev.piece.end.line] - lineStarts[prev.piece.end.line - 1] - 1 };
1692
// \r\n
1693
newEnd = { line: prev.piece.end.line, column: prev.piece.end.column - 1 };
1694
}
1696
>
const prevNewLength = prev.piece.length - 1;
1697
>
const prevNewLFCnt = prev.piece.lineFeedCnt - 1;
1698
>
prev.piece = new Piece(
1699
>
prev.piece.bufferIndex,
1700
>
prev.piece.start,
1701
>
newEnd,
1702
>
prevNewLFCnt,
1703
>
prevNewLength
1704
>
);
1705
>
1706
>
updateTreeMetadata(this, prev, -1, -1);
1707
>
if (prev.piece.length === 0) {
1708
nodesToDel.push(prev);
1709
}
1711
>
// update nextNode
1712
>
const newStart: BufferCursor = { line: next.piece.start.line + 1, column: 0 };
1713
>
const newLength = next.piece.length - 1;
1714
>
const newLineFeedCnt = this.getLineFeedCnt(next.piece.bufferIndex, newStart, next.piece.end);
1715
>
next.piece = new Piece(
1716
>
next.piece.bufferIndex,
1717
>
newStart,
1718
>
next.piece.end,
1719
>
newLineFeedCnt,
1720
>
newLength
1721
>
);
1722
>
1723
>
updateTreeMetadata(this, next, -1, -1);
1724
>
if (next.piece.length === 0) {
1725
nodesToDel.push(next);
1726
}
1728
>
// create new piece which contains \r\n
1729
>
const pieces = this.createNewPieces('\r\n');
1730
>
this.rbInsertRight(prev, pieces[0]);
1731
>
// delete empty nodes
1732
>
1733
>
for (let i = 0; i < nodesToDel.length; i++) {
1734
rbDelete(this, nodesToDel[i]);
1735
}
1737
1738
private adjustCarriageReturnFromNext(value: string, node: TreeNode): boolean {