duskmoon_code_engine library
Pure Dart code editor engine with incremental parsing.
A ground-up port of the CodeMirror 6 architecture for Flutter, providing document model, state management, syntax highlighting, and an interactive editor widget.
Quick Start
import 'package:duskmoon_code_engine/duskmoon_code_engine.dart';
CodeEditorWidget(
initialDoc: 'print("hello")',
language: dartLanguageSupport(),
theme: EditorTheme.dark(),
lineNumbers: true,
)
Supported Languages
19 languages: Dart, JavaScript/TypeScript, Python, HTML, CSS, JSON, Markdown, Rust, Go, YAML, C/C++, Elixir, Java, Kotlin, PHP, Ruby, Erlang, Swift, Zig.
Key Classes
- CodeEditorWidget — the main editor widget
- EditorViewController — programmatic editor control
- EditorState — immutable editor state snapshot
- EditorTheme — editor visual theme configuration
- Language / LanguageSupport — language definitions
- EditorCommands — standard editing commands
Classes
-
Annotation<
T> - An annotation instance carrying a typed value.
- Annotations
- Well-known annotations used by the core system.
-
AnnotationType<
T> - Typed key for attaching metadata to transactions.
- BracketMatching
- BracketPair
- A matched pair of bracket positions in the document.
- ChangedRange
- A range of the document that changed (for incremental parsing).
- ChangeSet
- An immutable, composable representation of one or more document edits.
- ChangeSpec
- A single edit specification: replace the range from..to with insert.
- ClipboardCommands
- Clipboard operations: copy, cut, and paste.
- CodeEditorWidget
- A read/write code editor with syntax highlighting and optional line numbers.
- CommentCommands
- CommentTokens
- Compartment
- Dynamic reconfiguration boundary.
- CompartmentExtension
- An extension wrapped in a Compartment for dynamic reconfiguration.
- CursorBlink
- DmCodeEditor
- A batteries-included code editor with configurable top and bottom bars.
- DmCodeEditorStatusBar
- Default bottom bar for DmCodeEditor.
- DmCodeEditorToolbar
- Default top bar for DmCodeEditor.
- DmEditorAction
- An action button displayed in DmCodeEditorToolbar.
- Document
- Immutable document backed by a Rope. Every edit produces a new Document via replace.
- EditorCommands
- A collection of standard editor commands that produce TransactionSpecs.
- EditorSelection
- The editor's selection state: one or more SelectionRanges.
- EditorState
- The immutable state of the code editor.
- EditorTheme
- EditorView
- Non-widget controller that holds state and dispatches transactions.
- EditorViewController
- Consumer-facing controller that wraps EditorView with convenience methods.
- EditorViewport
- Calculates which document lines are visible in the editor viewport. Assumes fixed line height (monospace) for O(1) line↔pixel mapping.
- Extension
- The base type for all editor extensions.
- ExtensionGroup
- An extension that bundles multiple child extensions.
- ExternalTokenizer
- Interface for external tokenizers.
-
Facet<
Input, Output> - A typed extension point that collects values from multiple providers and reduces them with a combine function.
-
FacetExtension<
Input, Output> - An extension that provides a value to a Facet.
- FacetStore
- Resolved facet values from a set of extensions.
- FoldDetector
- FoldRegion
- A foldable region in the document (both bounds are 1-based line numbers).
- GrammarData
- Serialized grammar data for an LR parser.
- GutterPainter
- HighlightBuilder
- Converts a syntax Tree into a flat list of InlineSpans for rendering.
- HighlightStyle
- HistoryEntry
- A single undo/redo entry: an inverse ChangeSet and the EditorSelection to restore when this entry is applied.
- HistoryState
- Immutable snapshot of the undo/redo stacks.
- InlineSpan
-
A styled text span covering
from..toin the document. - InputHandler
- TextInputClient adapter for EditorView.
- KeyBinding
- Associates a key descriptor string with one or two Command functions.
- Keymap
- A collection of KeyBindings that can be queried to dispatch key events.
- Language
- LanguageData
- Metadata about a language.
- LanguageRegistry
- LanguageSupport
- Line
- A single line in a document.
- LineColumn
- LinePainter
- LRParser
- A simplified LR parser that performs character-class-based tokenization and wraps results in a Tree.
-
NodeProp<
T> - A property that can be attached to a NodeType.
- NodeSet
- An indexed collection of NodeTypes.
- NodeType
- Describes the type of a syntax tree node.
- Parser
- Abstract interface for parsers.
- PositionUtils
- PrecedenceExtension
- An extension wrapped with a precedence level.
- Range
- A from/to range in a document.
- Rope
- An immutable rope — a balanced binary tree of text chunks.
- RopeBranch
- An internal branch node that combines two child nodes.
- RopeLeaf
-
A leaf node that holds raw text (at most
_maxLeafSizecharacters). - RopeNode
- A node in the rope tree.
- SearchCommands
- Commands that operate on a pre-computed list of SearchMatches.
- SearchMatch
- A single match found by a search query: the half-open range [from, to).
- SearchPanel
- A compact find/replace bar displayed at the top of the code editor.
- SearchState
- Pure search logic over a Document.
- SelectionPainter
- SelectionRange
- A single selection range with an anchor and head (cursor position).
-
StateEffect<
T> - An effect instance carrying a typed value.
-
StateEffectType<
T> - Typed marker for describing side effects in transactions.
-
StateField<
T> - Persistent state attached to EditorState, updated per transaction.
- StreamLanguage
- A simple regex-based tokenizer implementing Parser.
- SyntaxNode
- Positioned reference into a syntax tree for navigation.
- Tag
- TagStyle
- Token
- A token produced by tokenization.
- TokenRule
- A rule that maps a regex pattern to a node name.
- Transaction
- An immutable representation of a state change.
- TransactionSpec
- Specification for creating a Transaction.
- Tree
- Immutable syntax tree. Children stored as parallel lists.
- TreeBuffer
-
Compact flat representation for leaf/simple nodes.
Buffer:
typeId, from, to, endIndexper node. - TreeCursor
- Efficient stateful cursor for tree traversal. Uses a stack internally.
Enums
- Precedence
- Precedence levels for extension ordering.
Properties
- defaultDarkHighlight → HighlightStyle
-
final
- defaultLightHighlight → HighlightStyle
-
final
Functions
-
cLanguageSupport(
) → LanguageSupport -
cssLanguageSupport(
) → LanguageSupport -
dartLanguageSupport(
) → LanguageSupport -
defaultKeymap(
) → Keymap - Returns the default Keymap with standard editor key bindings.
-
elixirLanguageSupport(
) → LanguageSupport -
erlangLanguageSupport(
) → LanguageSupport -
goLanguageSupport(
) → LanguageSupport -
historyExtension(
) → Extension -
Returns the
historyFieldas an Extension to include in EditorState.create. -
htmlLanguageSupport(
) → LanguageSupport -
javaLanguageSupport(
) → LanguageSupport -
javascriptLanguageSupport(
) → LanguageSupport -
jsonHighlightMapping(
) → Map< String, Tag> -
jsonLanguageSupport(
) → LanguageSupport -
kotlinLanguageSupport(
) → LanguageSupport -
markdownLanguageSupport(
) → LanguageSupport -
phpLanguageSupport(
) → LanguageSupport -
prec(
Precedence p, Extension ext) → Extension - Wrap an extension with a precedence level.
-
pythonLanguageSupport(
) → LanguageSupport -
rubyLanguageSupport(
) → LanguageSupport -
rustLanguageSupport(
) → LanguageSupport -
swiftLanguageSupport(
) → LanguageSupport -
syntaxTree(
dynamic state) → Tree? - Get the current syntax tree from an EditorState.
-
syntaxTreeAvailable(
dynamic state) → bool - Check if a complete syntax tree is available.
-
yamlLanguageSupport(
) → LanguageSupport -
zigLanguageSupport(
) → LanguageSupport