Editor System
Inkdown uses CodeMirror 6 as its markdown editor. The editor system provides a clean abstraction layer that allows plugins to interact with the editor without knowing platform-specific details.Architecture Overview
EditorRegistry
Location:packages/core/src/EditorRegistry.ts
The EditorRegistry manages CodeMirror 6 EditorView instances and tracks which editor is currently active.
API
Usage in React Components
EditorStateManager
Location:packages/core/src/EditorStateManager.ts
Manages the content of open files, tracks dirty state (unsaved changes), and handles auto-saving.
Features
- Content Management: Stores editor content separately from file system
- Dirty Tracking: Knows which files have unsaved changes
- Auto-save: Automatically saves dirty files at intervals
- Debounced Saves: Prevents excessive writes during typing
API
EditorAdapter
Location:packages/core/src/editor/EditorAdapter.ts
Provides a plugin-friendly API for interacting with CodeMirror. This adapter wraps the CodeMirror EditorView to provide a stable API that plugins can depend on.
API
Position Interface
Plugin Integration
Registering Editor Extensions
Plugins can register CodeMirror extensions that are applied to all editor instances:Accessing the Editor
Plugins can access the active editor through the Workspace:CodeMirror 6 Extensions
Inkdown includes several built-in CodeMirror extensions:Core Extensions
- Markdown Language Support: Syntax highlighting for markdown
- Line Numbers: Optional line numbers in the gutter
- Line Wrapping: Soft wrap long lines
- Auto-close Brackets: Automatically close
(),[],{} - Vim Mode: Optional Vim keybindings
- Bracket Matching: Highlight matching brackets
- Search: Find and replace functionality
- History: Undo/redo support
Editor Configuration
Editor behavior is configured through theeditor config:
Platform Implementations
Desktop (Tauri)
On desktop, CodeMirror 6 runs directly in the React app:Mobile (React Native)
On mobile, CodeMirror runs inside a WebView with a JavaScript bridge for communication:Editor Events
The App handles editor events and routes them to appropriate systems:Editor Suggest
Location:packages/core/src/components/EditorSuggest.ts
Editor suggests provide autocomplete functionality (like [[ for links):
Related Documentation
- Architecture Overview - High-level architecture
- App and Managers - Manager APIs
- Plugin Development - Creating plugins with editor extensions
- CodeMirror 6 Documentation - Official CodeMirror docs
