Singapore
DocsGitHub
docs/guides/documents.md

Documents and sessions

Open a named document when text needs an identity shared with tabs, persistence or a language server. You need a mounted editor.

1. Choose plain text or a document

setText works for unnamed text. openDocument adds documentId and optional language metadata.

import { Editor } from '@singapore-editor/core/editor'const editor = new Editor(document.querySelector<HTMLElement>('#editor')!)editor.openDocument({ documentId: '/notes/todo.txt', text: 'Ship the docs\n' })const savedText = editor.materializeFullText()console.log(savedText)

2. Save through your application

Read the text when your application's save action runs. The editor's document id supplies identity; your application owns disk, network and persistence policy.

3. Share deliberately

The @singapore-editor/core/document entry point exposes document sessions and snapshots. A shared session lets several views refer to one buffer. Keep its owner alive while views need it, and close it through that owner after the last view releases it. Consult the generated document reference before building split-view ownership.

Sharing text and sharing an LSP session are separate decisions. The language-server packages expose shared sessions and connection pools for hosts with many tabs. Follow their ownership contracts when supplying external sessions.

4. Release the view

Call editor.dispose() when removing its container. Framework adapters handle disposal with the component owner. External services and sessions you supply remain your application's responsibility according to their API contracts.

If it doesn't work

A language server opens the wrong file

Use a stable path-like document id and a matching root URI. Check the Language servers guide's URI mapping.

Two views stop updating together

Confirm that both views use the same document session and that a closing view has not disposed the shared owner.

Continue with versioned documents, anchors and language servers.