Installation
Enable thecode-editor feature in your Cargo.toml:
Basic Usage
Features
- Syntax Highlighting: Built-in support for multiple programming languages
- Line Numbers: Optional gutter with line numbers
- Customizable Themes: Full control over editor appearance and syntax colors
- Rope-based Text Storage: Efficient text editing using the
ropeycrate - Read-only Mode: Display code without allowing edits
- Whitespace Visualization: Show leading whitespace characters
Supported Languages
The editor supports syntax highlighting for:- Rust
- Python
- JavaScript
- TypeScript
- Markdown
- TOML
- JSON
Customization
Editor Theme
Customize the editor’s appearance:Syntax Theme
Customize syntax highlighting colors:Configuration Options
Loading Files
Key Types
CodeEditorData
The main data structure that holds the editor state:EditorTheme
Controls the editor’s visual appearance:SyntaxTheme
Controls syntax highlighting colors:Example: Complete Editor
Notes
- The editor uses the
ropeycrate for efficient text handling - Syntax parsing happens on-demand via
editor.parse() - Call
editor.measure(font_size)after loading content - The editor is a fully reactive component that updates when the state changes