Package-level declarations

Types

Link copied to clipboard
data class BidiSpan(val from: Int, val to: Int, val level: Int)

A bidi span records a range of text with a uniform bidi level. Even levels are LTR, odd levels are RTL.

Link copied to clipboard
data class BlockCursorSpec(val offset: Int, val alpha: Float = 1.0f)

A block cursor position to render as an overlay rectangle.

Link copied to clipboard
data class BlockInfo(val from: Int, val to: Int, val top: Float, val height: Float, val type: BlockType, val widget: WidgetType? = null)

Describes a vertical block in the editor layout — either a text line or a widget.

Link copied to clipboard

The kinds of vertical blocks that make up the editor layout.

Link copied to clipboard
sealed class Decoration : RangeValue

Base class for all decoration types.

Link copied to clipboard

A set of decorations.

Link copied to clipboard

A plugin value that contributes decorations.

Link copied to clipboard

Text direction.

Link copied to clipboard
data class EditorLayout(val gutterStartPadding: Dp = 5.dp, val gutterEndPadding: Dp = 3.dp, val customGutterWidth: Dp = 14.dp, val contentTopPadding: Dp = 4.dp, val contentBottomPadding: Dp = 4.dp, val panelBorderWidth: Dp = 1.dp, val dropCursorWidth: Dp = 2.dp)

Layout measurements for the editor. Nested inside EditorTheme to separate layout concerns from color properties.

Link copied to clipboard
interface EditorSession

An editor session holds the editor state and dispatches transactions.

Link copied to clipboard
data class EditorTheme(val background: Color = Color(0xFF282C34), val foreground: Color = Color(0xFFABB2BF), val cursor: Color = Color(0xFF528BFF), val selection: Color = Color(0xFF3E4451), val activeLineBackground: Color = Color(0x0B6699FF), val gutterBackground: Color = Color(0xFF282C34), val gutterForeground: Color = Color(0xFF7D8799), val gutterActiveForeground: Color = Color(0xFFCCCCCC), val gutterBorderColor: Color = Color.Transparent, val searchMatchBackground: Color = Color(0x5972A1FF), val searchMatchSelectedBackground: Color = Color(0x2F6199FF), val selectionMatchBackground: Color = Color(0x1AAAFE66), val matchingBracketBackground: Color = Color(0x4400CC00), val nonMatchingBracketBackground: Color = Color(0x44CC0000), val panelBackground: Color = Color(0xFF282C34), val panelBorderColor: Color = Color(0xFF555555), val buttonBackground: Color = Color(0xFF393939), val buttonBorderColor: Color = Color(0xFF888888), val inputBackground: Color = Color(0xFF282C34), val inputBorderColor: Color = Color(0xFF555555), val tooltipBackground: Color = Color(0xFF353A42), val foldPlaceholderColor: Color = Color(0xFFDDDDDD), val foldPlaceholderBackground: Color = Color(0x33EEEEEE), val activeLineGutterBackground: Color = Color(0x0B6699FF), val dark: Boolean = true, val layout: EditorLayout = EditorLayout(), val extras: Map<ThemeKey<*>, Any?> = emptyMap())

Color/style tokens for the editor. Passed through a CompositionLocal so every composable in the editor tree can read them without prop-drilling.

Link copied to clipboard
data class GutterConfig(val type: GutterType? = null, val lineMarker: (EditorSession, Int) -> GutterMarker?? = null, val lineMarkerChange: (ViewUpdate) -> Boolean? = null, val lineMarkerClick: (EditorSession, Int) -> Boolean? = null, val renderEmptyElements: Boolean = false, val initialSpacer: (EditorSession) -> GutterMarker? = null, val updateSpacer: (GutterMarker, ViewUpdate) -> GutterMarker? = null)

Configuration for a gutter column.

Link copied to clipboard
abstract class GutterMarker : RangeValue

A gutter marker contributes to a specific line's gutter column.

Link copied to clipboard
sealed class GutterType

Identifies the type of a gutter column.

Link copied to clipboard
data class KeyBinding(val key: String? = null, val mac: String? = null, val win: String? = null, val linux: String? = null, val run: (EditorSession) -> Boolean? = null, val shift: (EditorSession) -> Boolean? = null, val any: (EditorSession, KeyEvent) -> Boolean? = null, val anyRaw: (EditorSession, String, Boolean, Boolean, Boolean, Boolean) -> Boolean? = null, val preventDefault: Boolean = false, val stopPropagation: Boolean = false)

A key binding maps a key name (e.g. "Ctrl-Enter") to a command.

Link copied to clipboard

Builder scope for defining key bindings via DSL.

Link copied to clipboard
annotation class KeymapDsl

Marks DSL scope for KeymapBuilder.

Link copied to clipboard

A line decoration adds attributes to the containing line element.

Link copied to clipboard
data class LineDecorationSpec(val cssClass: String? = null, val style: SpanStyle? = null)

Spec for a line decoration (whole-line styling).

Link copied to clipboard
data class LineGap(val from: Int, val to: Int, val size: Float)

A gap in the rendered document used for virtual scrolling when the document has many lines that are currently off-screen.

Link copied to clipboard
data class LineLayout(val lineNumber: Int, val lineFrom: Int, val topPx: Float, val leftPx: Float, val result: TextLayoutResult)

Cached layout result for a single document line.

Link copied to clipboard

A mark decoration applies styling to a range of text.

Link copied to clipboard
data class MarkDecorationSpec(val inclusive: Boolean = false, val inclusiveStart: Boolean = false, val inclusiveEnd: Boolean = false, val style: SpanStyle? = null, val paragraphStyle: ParagraphStyle? = null, val tagName: String? = null, val cssClass: String? = null)

Spec for a mark decoration (inline text styling).

Link copied to clipboard
class MatchDecorator(regexp: Regex, decorate: (add: (from: Int, to: Int, deco: Decoration) -> Unit, match: MatchResult, view: EditorSession) -> Unit, maxLength: Int)

Port of matchdecorator.ts — applies a decoration to every match of a regular expression in the visible document range.

Link copied to clipboard
data class Panel(val top: Boolean = false, val content: @Composable BoxScope.() -> Unit)

Describes a panel to show above or below the editor content.

Link copied to clipboard
data class PluginSpec<V : PluginValue>(val create: (EditorSession) -> V, val provide: (ViewPlugin<V>) -> Extension? = null, val decorations: (V) -> DecorationSet? = null)

Specification for a ViewPlugin.

Link copied to clipboard
interface PluginValue

A plugin value is the mutable instance managed by a ViewPlugin.

Link copied to clipboard
data class Rect(val left: Float, val top: Float, val right: Float, val bottom: Float)

A simple axis-aligned rectangle used for coordinate results.

Link copied to clipboard

A replace decoration hides a range of text, optionally showing a widget.

Link copied to clipboard
data class ReplaceDecorationSpec(val widget: WidgetType? = null, val inclusive: Boolean = false, val inclusiveStart: Boolean = false, val inclusiveEnd: Boolean = false, val block: Boolean = false)

Spec for a replace decoration (hides/replaces a range).

Link copied to clipboard
data class ScrollMarginSpec(val top: Float = 0.0f, val right: Float = 0.0f, val bottom: Float = 0.0f, val left: Float = 0.0f)

Margin spec for scroll target offsets.

Link copied to clipboard

How to position the viewport when scrolling to a target.

Link copied to clipboard
data class ScrollTarget(val from: Int, val to: Int, val y: ScrollStrategy = ScrollStrategy.Nearest, val x: ScrollStrategy = ScrollStrategy.Nearest, val yMargin: Float = 5.0f, val xMargin: Float = 5.0f)

Describes a scroll-into-view request.

Link copied to clipboard
class ThemeKey<T>(val default: T)

A typed key for extensible theme properties. Modules define their own keys with sensible defaults; themes can override them via themeExtras.

Link copied to clipboard
data class Tooltip(val pos: Int, val above: Boolean = false, val strictSide: Boolean = false, val content: @Composable () -> Unit)

Describes a tooltip to show near a document position.

Link copied to clipboard
class ViewPlugin<V : PluginValue>(val spec: PluginSpec<V>)

A view plugin contributes behaviour and/or decorations to the editor view.

Link copied to clipboard
data class Viewport(val from: Int, val to: Int)

The visible document range.

Link copied to clipboard
data class ViewState(val state: EditorState, val viewport: Viewport, val visibleRanges: List<Pair<Int, Int>> = emptyList(), val lineGaps: List<LineGap> = emptyList(), val scrollTarget: ScrollTarget? = null)

Snapshot of the view's layout state. Created fresh for each recomposition.

Link copied to clipboard
class ViewUpdate(val session: EditorSession, val state: EditorState, val transactions: List<Transaction>, val viewportChanged: Boolean = false, val heightChanged: Boolean = false, val focusChanged: Boolean = false)

Describes an update to the editor.

Link copied to clipboard

A widget decoration places a composable inside the text flow.

Link copied to clipboard
data class WidgetDecorationSpec(val widget: WidgetType, val side: Int = 0, val inlineOrder: Boolean = false, val block: Boolean = false)

Spec for a widget decoration (inline widget).

Link copied to clipboard
abstract class WidgetType

Base class for custom inline/block widgets. Subclasses implement Content as a Compose composable instead of toDOM().

Properties

Link copied to clipboard

Facet for marking ranges as "atomic" — the cursor won't stop inside them.

Link copied to clipboard

Facet for extensions that provide block cursor positions.

Link copied to clipboard

Copy the current selection to the system clipboard.

Link copied to clipboard

Cut the current selection: copy to clipboard and delete.

Link copied to clipboard

Paste text from the system clipboard at the current cursor position.

Link copied to clipboard

Extra key/value attributes for the editor content element.

Link copied to clipboard

Extension that changes the cursor to a crosshair when Alt is held, indicating rectangular selection mode is available.

Link copied to clipboard

Facet for contributing decoration sets from extensions and plugins. Multiple sources are collected into a list.

Link copied to clipboard

Default content text style with font metrics but no color.

Link copied to clipboard

Default font family for the editor.

Link copied to clipboard

A default dark theme.

Link copied to clipboard

Extension to select the draw-selection extension.

Link copied to clipboard

Extension that shows a cursor at the position where a drag is currently hovering, to indicate where a drop would land.

Link copied to clipboard

Whether the editor content is editable.

Link copied to clipboard

Extra key/value attributes for the outer editor wrapper element.

Link copied to clipboard

Facet for editor content text styling (font family, size, line height, color).

Link copied to clipboard
Link copied to clipboard

Facet that lets extensions override the editor theme.

Link copied to clipboard

Facet for registering an exception handler. When an extension throws an exception, it can be reported through this handler instead of crashing the editor. If no handler is configured, the exception is printed to stderr.

Link copied to clipboard

Facet that collects all registered gutter configurations.

Link copied to clipboard

Extension that highlights the line containing the primary cursor.

Link copied to clipboard

Extension that highlights the active line's gutter entry. Works in conjunction with highlightActiveLine.

Link copied to clipboard

Extension that highlights special (non-printing) characters with a placeholder widget.

Link copied to clipboard

Extension that highlights trailing whitespace (spaces and tabs at end of lines) with a warning-style background.

Link copied to clipboard

Extension that makes whitespace characters (spaces and tabs) visible by applying a subtle mark decoration. Spaces are shown with a centered dot character and tabs with an arrow.

Link copied to clipboard

Facet for extensions that need to suppress text input under certain conditions.

Link copied to clipboard

Facet that collects all key bindings from extensions.

Link copied to clipboard

A light theme.

Link copied to clipboard
val lineNumberMarkers: Facet<(view: EditorSession, lineFrom: Int) -> GutterMarker?, List<(view: EditorSession, lineFrom: Int) -> GutterMarker?>>

Facet that allows extensions to contribute custom GutterMarkers to the line number gutter column. Each provider maps a line start position to an optional marker.

Link copied to clipboard

Extension that adds line numbers to the editor gutter.

Link copied to clipboard

Extension that enables soft line wrapping.

Link copied to clipboard

CompositionLocal that provides the resolved content text style.

Link copied to clipboard

CompositionLocal that provides the current EditorSession to panel and tooltip composables.

Link copied to clipboard

CompositionLocal that provides the current EditorTheme.

Link copied to clipboard
val onSave: Facet<suspend (EditorSession) -> Unit, List<suspend (EditorSession) -> Unit>>

Facet that collects save handlers.

Link copied to clipboard

The facet that provides all active panels. This is an alias for showPanels, exported under a name matching the upstream CodeMirror API.

Link copied to clipboard

Facet for per-line class names added by extensions.

Link copied to clipboard

Extension that enables rectangular (column-mode) selection when the user Alt-drags through the editor.

Link copied to clipboard

Extension that binds Ctrl-S (and Cmd-S on macOS) to the save command.

Link copied to clipboard

Scroll margins around the cursor (pixels on each side).

Link copied to clipboard

A Saver for SelectionRange that serializes to JSON.

Link copied to clipboard

Facet that provides panels to display around the editor.

Link copied to clipboard

Facet for multiple simultaneous panels.

Link copied to clipboard

Facet that provides a single tooltip at a time.

Link copied to clipboard

Facet that provides multiple simultaneous tooltips.

Link copied to clipboard

Background color for special (non-printing) character placeholders.

Link copied to clipboard

Text color for special (non-printing) character placeholders.

Link copied to clipboard

Default regex that matches special / control characters to highlight.

Link copied to clipboard

Tab rendering extension.

Link copied to clipboard

A Saver for Text that serializes to its string representation.

Link copied to clipboard

Background color for trailing whitespace.

Link copied to clipboard

Color for visible whitespace marks (spaces and tabs).

Functions

Link copied to clipboard

Convenience extension to build a SpanStyle for active line.

Link copied to clipboard

Programmatically close all hover tooltips in the given session.

Link copied to clipboard

Delete the text between from and to.

Link copied to clipboard

Dispatch a transaction built via DSL.

Link copied to clipboard
fun Modifier.drawSelectionOverlay(state: EditorState, lineFrom: Int, lineTo: Int, theme: EditorTheme, textLayoutResult: TextLayoutResult? = null, tabOffsetMap: IntArray? = null): Modifier

Draw the cursor and selection ranges as a per-line Modifier overlay.

Link copied to clipboard
fun EditorSession(initialState: EditorState, onUpdate: (Transaction) -> Unit = {}): EditorSession

Create an EditorSession with the given initial state and optional update callback.

Link copied to clipboard
fun EditorSessionSaver(extensions: Extension? = null, fields: Map<String, StateField<*>>? = null, onUpdate: (Transaction) -> Unit = {}): Saver<EditorSession, String>

Create a Saver for EditorSession that preserves the document and selection across configuration changes and process death.

Link copied to clipboard
fun EditorStateSaver(extensions: Extension? = null, fields: Map<String, StateField<*>>? = null): Saver<EditorState, String>

Create a Saver for EditorState that preserves the document and selection.

Link copied to clipboard
fun editorThemeFromColors(background: Color, foreground: Color, primary: Color, surface: Color, outline: Color, dark: Boolean): EditorTheme

Create an EditorTheme from semantic color values, designed for easy integration with Material Design color schemes.

Link copied to clipboard

Get all active panels in the given state.

Link copied to clipboard

Get all active tooltips in the given state, including both facet-provided tooltips and hover tooltips.

Link copied to clipboard
fun groupAt(state: EditorState, pos: DocPos, side: Int = 1): CharCategory

Find the character group (word/space/punctuation) at the given position.

Link copied to clipboard

Create an extension that adds a gutter column.

Link copied to clipboard
fun GutterView(session: EditorSession, lineNumber: Int, modifier: Modifier = Modifier)

A composable that renders all registered gutter columns alongside the editor content.

Link copied to clipboard

Check whether any hover tooltips are currently active in the given session.

Link copied to clipboard

Show a hover tooltip when the user points at text matching source.

Link copied to clipboard

Insert text at the given pos in the document.

Link copied to clipboard
expect fun keyEventLayoutKey(event: KeyEvent): String?

Extract the layout-aware key name from a KeyEvent for shortcut matching.

actual fun keyEventLayoutKey(event: KeyEvent): String?

Extract the layout-aware key name from a KeyEvent for shortcut matching.

actual fun keyEventLayoutKey(event: KeyEvent): String?

Extract the layout-aware key name from a KeyEvent for shortcut matching.

actual fun keyEventLayoutKey(event: KeyEvent): String?

Extract the layout-aware key name from a KeyEvent for shortcut matching.

Link copied to clipboard
inline fun keymapOf(block: KeymapBuilder.() -> Unit): Extension

Create a keymap extension using a DSL builder.

Convenience: create an extension from a list of key bindings.

fun keymapOf(vararg bindings: KeyBinding): Extension

Convenience: create an extension from key bindings.

Link copied to clipboard
fun KodeMirror(session: EditorSession, modifier: Modifier = Modifier)

The main editor composable.

Link copied to clipboard
fun logException(state: EditorState, exception: Throwable)

Log an exception that occurred during extension execution. Reports to handlers registered via exceptionSink, or prints to stderr if none are configured.

Link copied to clipboard
fun moveByChar(state: EditorState, sel: SelectionRange, forward: Boolean, extend: Boolean = false): SelectionRange

Move a selection range one character in forward direction, extending if extend is true, otherwise collapsing.

Link copied to clipboard
fun moveByGroup(state: EditorState, sel: SelectionRange, forward: Boolean, extend: Boolean = false): SelectionRange

Move a selection range by one word group in forward direction.

Link copied to clipboard
fun moveBySubword(state: EditorState, sel: SelectionRange, forward: Boolean, extend: Boolean = false): SelectionRange

Move a selection range by one subword in forward direction.

Link copied to clipboard
fun moveVertically(view: EditorSession, sel: SelectionRange, forward: Boolean, extend: Boolean = false): SelectionRange

Move a selection range vertically by one line, keeping an approximate horizontal position.

Link copied to clipboard
fun onChange(callback: (String) -> Unit): Extension

Create an extension that calls callback with the full document text whenever the document changes.

Link copied to clipboard
fun onChangeAsync(callback: suspend CoroutineScope.(String) -> Unit): Extension

Create an extension that launches callback in a coroutine whenever the document changes.

Link copied to clipboard

Create an extension that calls callback with the current selection whenever the selection changes.

Link copied to clipboard
fun onSelectionAsync(callback: suspend CoroutineScope.(EditorSelection) -> Unit): Extension

Create an extension that launches callback in a coroutine whenever the selection changes.

Link copied to clipboard
fun PanelLayout(view: EditorSession, modifier: Modifier = Modifier, content: @Composable () -> Unit)

A layout composable that wraps the editor content with top/bottom panels.

Link copied to clipboard
fun placeholder(content: @Composable () -> Unit): Extension

Create an extension that shows a composable widget as placeholder content when the document is empty.

Create an extension that shows text as placeholder text when the document is empty.

Link copied to clipboard
operator fun EditorTheme.plus(extras: Map<ThemeKey<*>, Any?>): EditorTheme

Merge additional extras into this theme's extras map.

Link copied to clipboard

Create and remember an EditorSession from an EditorStateConfig.

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

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

Link copied to clipboard

Remember the current value of a Facet, recomposing only when its value changes.

Link copied to clipboard

Remember the current value of a StateField, recomposing only when its value changes.

Link copied to clipboard
fun rememberSaveableEditorSession(doc: String = "", extensions: Extension? = null, fields: Map<String, StateField<*>>? = null, onUpdate: (Transaction) -> Unit = {}): EditorSession

Create and remember an EditorSession that survives configuration changes and process death via rememberSaveable.

Link copied to clipboard

Force repositioning of all tooltips. In Compose, tooltips are automatically repositioned via state changes, so this is effectively a no-op. Provided for API compatibility with upstream CodeMirror.

Link copied to clipboard
fun save(session: EditorSession): Boolean

Command that invokes all registered onSave handlers.

Link copied to clipboard
fun scrollPastEnd(padding: Dp = 200.dp): Extension

Extension that adds empty space after the last line of the document, allowing the user to scroll so the last line sits at the top.

Link copied to clipboard
fun EditorSession.select(anchor: DocPos, head: DocPos = anchor)

Set the selection to a range from anchor to head. If head is not provided, creates a cursor at anchor.

Link copied to clipboard

Select the entire document.

Link copied to clipboard

Convenience extension to build a SpanStyle from theme colors.

Link copied to clipboard

Replace the entire document content with text.

Link copied to clipboard
fun themeExtras(vararg entries: Pair<ThemeKey<*>, Any?>): Map<ThemeKey<*>, Any?>

Build a theme extras map from key-value pairs.

Link copied to clipboard

A composable layer that renders all active tooltips using Popup.