@singapore-editor/textbuffer
v0.2.9
Published
A persistent piece-table text buffer with snapshots, stable anchors, and line mapping.
Maintainers
Readme
@singapore-editor/textbuffer
A persistent piece-table text buffer with snapshots, stable anchors, and line mapping.
Part of Singapore. A code editor for the browser that keeps every version.
Install
npm install @singapore-editor/textbufferUsage
import {
createPieceTableSnapshot,
insertIntoPieceTable,
materializePieceTableFullText,
} from '@singapore-editor/textbuffer'
const original = createPieceTableSnapshot('hello')
const edited = insertIntoPieceTable(original, 5, ' world')
const branch = insertIntoPieceTable(original, 0, 'say ')
materializePieceTableFullText(original) // 'hello'
materializePieceTableFullText(edited) // 'hello world'
materializePieceTableFullText(branch) // 'say hello'API highlights
createPieceTableSnapshot()loads text.insertIntoPieceTable()returns a new snapshot.anchorAt()andresolveAnchor()track positions through edits.
In the Singapore family
You can use this package on its own. @singapore-editor/core owns editor views; optional packages add syntax, search, gutters, and language features.
Singapore README · Documentation
License
MIT. License
