Singapore
DocsGitHub

A code editor for the browser that keeps every version.

Singapore is a modular code editor component. Each edit makes a new version of a persistent piece table, and anchors follow text through edits. Parsing, highlighting and language servers run in workers.

import {
anchorAfter,
createPieceTableSnapsh
ot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableF
ullText as text,
resolveAnchor,
} from
'@singapore-editor/tex
tbuffer'
// Every edit returns
a new version. Old
versions stay
readable.
const first =
createPieceTableSnapsh
ot('hello')
const second =
insertIntoPieceTable(f
irst, 5, ' world')
const branch =
insertIntoPieceTable(f
irst, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello
world'
text(branch) // 'say
hello'
// An anchor follows
its text through later
edits.
const world =
anchorAfter(second, 6)
const third =
deleteFromPieceTable(s
econd, 0, 6)
resolveAnchor(third,
world) // { offset: 0,
liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapsh
ot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableF
ullText as text,
resolveAnchor,
} from
'@singapore-editor/tex
tbuffer'
// Every edit returns
a new version. Old
versions stay
readable.
const first =
createPieceTableSnapsh
ot('hello')
const second =
insertIntoPieceTable(f
irst, 5, ' world')
const branch =
insertIntoPieceTable(f
irst, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello
world'
text(branch) // 'say
hello'
// An anchor follows
its text through later
edits.
const world =
anchorAfter(second, 6)
const third =
deleteFromPieceTable(s
econd, 0, 6)
resolveAnchor(third,
world) // { offset: 0,
liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullTex
t as text,
resolveAnchor,
} from
'@singapore-editor/textbuffe
r'
// Every edit returns a new
version. Old versions stay
readable.
const first =
createPieceTableSnapshot('he
llo')
const second =
insertIntoPieceTable(first,
5, ' world')
const branch =
insertIntoPieceTable(first,
0, 'say ')
text(first) // 'hello'
text(second) // 'hello
world'
text(branch) // 'say hello'
// An anchor follows its
text through later edits.
const world =
anchorAfter(second, 6)
const third =
deleteFromPieceTable(second,
0, 6)
resolveAnchor(third, world)
// { offset: 0, liveness:
'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullTex
t as text,
resolveAnchor,
} from
'@singapore-editor/textbuffe
r'
// Every edit returns a new
version. Old versions stay
readable.
const first =
createPieceTableSnapshot('he
llo')
const second =
insertIntoPieceTable(first,
5, ' world')
const branch =
insertIntoPieceTable(first,
0, 'say ')
text(first) // 'hello'
text(second) // 'hello
world'
text(branch) // 'say hello'
// An anchor follows its
text through later edits.
const world =
anchorAfter(second, 6)
const third =
deleteFromPieceTable(second,
0, 6)
resolveAnchor(third, world)
// { offset: 0, liveness:
'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as
text,
resolveAnchor,
} from
'@singapore-editor/textbuffer'
// Every edit returns a new version.
Old versions stay readable.
const first =
createPieceTableSnapshot('hello')
const second =
insertIntoPieceTable(first, 5, '
world')
const branch =
insertIntoPieceTable(first, 0, 'say
')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text
through later edits.
const world = anchorAfter(second, 6)
const third =
deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // {
offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as
text,
resolveAnchor,
} from
'@singapore-editor/textbuffer'
// Every edit returns a new version.
Old versions stay readable.
const first =
createPieceTableSnapshot('hello')
const second =
insertIntoPieceTable(first, 5, '
world')
const branch =
insertIntoPieceTable(first, 0, 'say
')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text
through later edits.
const world = anchorAfter(second, 6)
const third =
deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // {
offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions
stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, '
world')
const branch = insertIntoPieceTable(first, 0, 'say
')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0,
liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions
stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, '
world')
const branch = insertIntoPieceTable(first, 0, 'say
')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0,
liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, ' world')
const branch = insertIntoPieceTable(first, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, ' world')
const branch = insertIntoPieceTable(first, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, ' world')
const branch = insertIntoPieceTable(first, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, ' world')
const branch = insertIntoPieceTable(first, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, ' world')
const branch = insertIntoPieceTable(first, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0, liveness: 'live' }
import {
anchorAfter,
createPieceTableSnapshot,
deleteFromPieceTable,
insertIntoPieceTable,
materializePieceTableFullText as text,
resolveAnchor,
} from '@singapore-editor/textbuffer'
// Every edit returns a new version. Old versions stay readable.
const first = createPieceTableSnapshot('hello')
const second = insertIntoPieceTable(first, 5, ' world')
const branch = insertIntoPieceTable(first, 0, 'say ')
text(first) // 'hello'
text(second) // 'hello world'
text(branch) // 'say hello'
// An anchor follows its text through later edits.
const world = anchorAfter(second, 6)
const third = deleteFromPieceTable(second, 0, 6)
resolveAnchor(third, world) // { offset: 0, liveness: 'live' }
This is a Singapore editor, configured for TypeScript.

Install

npm install
@singapore-editor/core
npm install
@singapore-editor/core
npm install
@singapore-editor/core
npm install
@singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
npm install @singapore-editor/core
shellscript example

Then follow the quick start. The docs explain how to configure and use the editor.

Start here

Limits

The public API is still changing. Rows have fixed height, syntax colours cannot use bold or italic, and mobile is not a supported target. Touch selection exists in the source as an experiment, outside the npm packages. There is no published editor-level benchmark against Monaco or CodeMirror yet.