A TypeScript implementation of the piece table data structure with red-black tree, multiple buffered and optimized by for line model.
The repository is almost rewritten by myself from the VSCode's piece-table version. Almost nothing new except more readable coding styles and comments.
- The piece table is written using red-black tree as the balanced binary tree.
- The piece table may handle all the possible end-of-line cases correctly.
- If you are interest in more details about the idea, see the following link from the blog of VSCode.
You may use PieceTableBuilder
to build PieceTable
for yourself as following:
function buildPieceTable(contents: string[], normalizationEOL?: boolean, defaultEOL?: EndOfLineType, force?: boolean): IPieceTable {
const builder = new PieceTableBuilder();
for (const content of contents) {
builder.receive(content);
}
builder.build();
return builder.create(normalizationEOL, defaultEOL, force);
}
npm run test