rememberEditorSession

fun rememberEditorSession(doc: String = "", extensions: Extension? = null, onUpdate: (Transaction) -> Unit = {}): EditorSession

Create and remember an EditorSession with the given document text and extensions.

Initial-value-only parameters: doc and extensions are used only when the session is first created. Subsequent recompositions with different values have no effect — the session retains the state from its initial creation, including cursor position, selection, and undo history.

This matches CodeMirror 6's model, where an EditorState (and the view that owns it) is created once and then mutated exclusively through transactions. To update the document or reconfigure extensions after creation, dispatch a transaction via EditorSession.dispatch:

// Update document content
session.dispatch(TransactionSpec(changes = ChangeSpec.Single(0, session.state.doc.length, newDoc.asInsert())))

// Reconfigure extensions
session.dispatch(TransactionSpec(effects = listOf(StateEffect.reconfigure(newExtensions))))

Parameters

doc

Initial document text. Ignored after first composition.

extensions

Initial set of extensions. Ignored after first composition.

onUpdate

Callback invoked for every transaction dispatched to the session.


Create and remember an EditorSession from an EditorStateConfig.

Initial-value-only parameter: config is used only when the session is first created. Subsequent recompositions with a different config have no effect — the session retains the state from its initial creation, including cursor position, selection, and undo history.

This matches CodeMirror 6's model, where an EditorState (and the view that owns it) is created once and then mutated exclusively through transactions. To update the document or reconfigure extensions after creation, dispatch a transaction via EditorSession.dispatch.

Parameters

config

Initial editor state configuration. Ignored after first composition.

onUpdate

Callback invoked for every transaction dispatched to the session.