@singapore-editor/core
v0.2.15
Published
The browser editor at the core of Singapore, with text editing, selections, undo history, themes, and plugins.
Maintainers
Readme
@singapore-editor/core
The browser editor at the core of Singapore, with text editing, selections, undo history, themes, and plugins.
Part of Singapore. A code editor for the browser that keeps every version.
Install
npm install @singapore-editor/coreUsage
import { Editor } from '@singapore-editor/core/editor'
const host = document.createElement('div')
host.style.height = '400px'
document.body.append(host)
const editor = new Editor(host)
editor.setText('const value = 1\n')
// Call editor.dispose() when removing the view.The editor's stylesheet loads with the module, through any bundler that handles CSS imports, such as Vite. Plugin packages load their own stylesheets the same way. Each package also exports style.css for pages that link the stylesheet themselves.
Content-height embedding
Use content mode for a code sample or document that scrolls with its page. Give the host its width and leave its height automatic.
Create the view with new Editor(host, { height: 'content', wordWrap: true }), then load the sample with setText().
Content mode paints every display row and grows after edits, font changes, preview replacements and resizing. Caret and search reveal scroll outside ancestors. setScrollMode('content') switches an existing view to this layout. static keeps its existing all-row layout with horizontal editor scrolling; virtualized keeps a bounded window of rows.
Use maxHeight to switch to internal scrolling when the document reaches a chosen height. See browser layout for the sizing and paint limits.
Touch selection
Status: experimental, in the source only. The npm releases (core 0.1.2, plugin-ui 0.1.0) have no touch code, and mobile is not a supported target.
Hold a word or double-tap it, keep that contact down, and drag by words across rows. Triple-tap selects a whole line and its held contact drags by lines. Four taps select the document. Ordinary swipes scroll. These gestures use the same document selections and boundaries as desktop clicks.
Touch menu chrome is opt-in through createTouchSelectionPlugin from @singapore-editor/plugin-ui/touch-selection-plugin. The plugin owns its menu, extension items and optional haptics. Core view contributions expose onDidTouchSelection, getTouchSelectionAnchor, getSelectedText, getInputCommandState and runInputCommand for input-aware plugins. Clipboard commands retain active paste providers and browser clipboard authorization.
What tests cover it:
- Unit tests for the gesture recognizer (
test/touchSelection.test.tsin this package) and the menu and plugin (packages/plugin-ui/test/touchSelection*.test.ts). - Playwright specs in
examples/app/test/mobile-*.spec.ts, which run in Chromium and WebKit with an iPhone 13 profile. The repository's CI workflows do not run them. Run them withbun run --cwd examples/app test:e2e. - Notes on a Mobile Safari run on the iOS 26.5 simulator in Browser quirks.
The automated tests above do not run on a physical phone, and Browser quirks lists physical-device haptic feedback as unverified.
VS Code themes and optional Shiki
@singapore-editor/core/rendering exports editorThemeFromVscodeTheme and related converters for VS Code theme definitions without pulling in Shiki or Oniguruma. For syntax colors, use @singapore-editor/tree-sitter or @singapore-editor/highlighting. If you specifically want Shiki or TextMate grammars, install the separate optional @singapore-editor/shiki package.
API highlights
Editor.setText()loads text into a view.openDocument()gives a document its own identity.dispose()releases the view and its plugins.
In the Singapore family
Start with @singapore-editor/core. Add optional packages for gutters, search, syntax, or language server features.
Singapore README · Documentation
License
MIT. License
