-
-
Notifications
You must be signed in to change notification settings - Fork 14
Code Editor
github-actions[bot] edited this page Apr 5, 2026
·
1 revision
The code_editor widget provides a full-featured code editing experience with syntax highlighting, line numbers, folding, search, and more.
Display syntax-highlighted code:
use blinc_layout::prelude::*;
use blinc_layout::syntax::{SyntaxConfig, RustHighlighter};
code(r#"fn main() { println!("Hello"); }"#)
.syntax(SyntaxConfig::new(RustHighlighter::new()))
.line_numbers(true)
.font_size(14.0)
.w_full()Full editor with Stateful incremental updates:
let state = code_editor_state("let x = 42;");
code_editor(&state)
.syntax(SyntaxConfig::new(RustHighlighter::new()))
.line_numbers(true)
.font_size(13.0)
.on_change(|new_content| {
println!("Content: {}", new_content);
})
.w_full()
.h(400.0)- Type, Enter (auto-indent), Backspace, Delete
- Tab / Shift+Tab: indent/dedent selected lines
- Cmd+Backspace/Delete: delete word backward/forward
- Arrow keys (with Shift for selection)
- Cmd+Left/Right: word jump
- Smart Home: toggle between first non-whitespace and column 0
- Page Up/Down
- Mouse click cursor positioning
- Cmd+C/X/V: copy/cut/paste
- Cmd+Z / Cmd+Shift+Z: undo/redo (200-entry history)
- Cmd+A: select all
- Syntax highlighting (Rust, JSON, or custom highlighters)
- Line numbers with gutter
- Current line highlight
- Selection rendering
- Bracket matching
- Indentation guides
- Code folding (click gutter chevrons)
- Minimap (optional scaled-down overview)
- VS Code-style search bar overlay
- Case sensitive, whole word, regex toggles
- Match highlighting with navigation (up/down arrows)
- Find and replace with replace all
Built-in highlighters:
use blinc_layout::syntax::*;
// Rust
SyntaxConfig::new(RustHighlighter::new())
// JSON
SyntaxConfig::new(JsonHighlighter::new())
// Plain text with custom colors
SyntaxConfig::new(
PlainHighlighter::new()
.text_color(Color::rgba(0.8, 0.9, 0.8, 1.0))
.background(Color::rgba(0.1, 0.12, 0.1, 1.0))
)Implement the SyntaxHighlighter trait:
struct MyHighlighter;
impl SyntaxHighlighter for MyHighlighter {
fn token_rules(&self) -> &[TokenRule] {
&[
TokenRule::new(r"//.*$", Color::GREEN, false, TokenType::Comment),
TokenRule::new(r#""[^"]*""#, Color::ORANGE, false, TokenType::String),
TokenRule::new(r"\b(fn|let|if|else)\b", Color::PURPLE, true, TokenType::Keyword),
]
}
fn default_color(&self) -> Color { Color::WHITE }
fn background_color(&self) -> Color { Color::rgb(0.1, 0.1, 0.12) }
}code_editor(&state)
.line_numbers(true) // Show line numbers
.font_size(13.0) // Font size in pixels
.line_height(1.5) // Line height multiplier
.padding(16.0) // Content padding
.code_bg(Color::BLACK) // Background color
.text_color(Color::WHITE) // Default text color
.edit(true) // Enable editing (default for code_editor)
.indent_guides(true) // Show vertical indent guides
.code_folding(true) // Enable fold/unfold
.minimap(true) // Show minimap sidebarGetting Started
Mobile Development
Example Gallery
- Example Gallery
- Canvas Element
- Canvas Kit Interactive
- Carousel Demo - Selector API Showcase
- Chrome-Style Tabs
- blinc_cn Components
- Code Element
- Complex SVG
- CSS Debug
- CSS Visual Features
- Layer Effects
- Emoji and HTML Entities
- @flow Shader
- Fluid Surface
- Skeleton animation with glTF +
blinc_canvas_kit. DrawContext::run_gpu_passend-to-end demo.- Image CSS Styling
- Image Layer Test
- Keyframe Animation Canvas
- Markdown Editor
- 3D Mesh Demo — renders the Khronos glTF
DamagedHelmetsample model - Motion Demo
- Music Player Glass Card
- Node-editor demo — pre-wired graph with three node types, typed
- Notch Menu Bar
- Overflow Fade
- Overlay System
- Pointer Query
- Rich Text Element
- Rich Text Editor
- Scroll Container
- Semantic @flow
- Sortable
- Stateful API + Signal-bound modifiers demo.
- End-to-end 3D demo wiring Blinc's SceneKit3D renderer up to
- Unified Styling API
- SVG Animation
- Table Builder
- Tabler Icons
- Minimal text positioning test
- Text Input Widgets
- KHR_texture_transform
- Theme System
- Timeline Animation
- Typography
- Video Player
- Wet Glass
- Windowed Application
Web Development
Core Concepts
Animation
Components
Component Library (blinc_cn)
Widgets
- Buttons & Inputs
- Text & Rich Text
- Code Editor
- Scroll Containers
- Virtualized List
- Canvas Drawing
- Images & SVG
- Audio & Video
- Markdown Rendering
Canvas Kit
Advanced
- Routing & Navigation
- Multi-Window
- System Integration
- Element Query API
- Overlay System
- Custom State Machines
- Pointer Query
- Performance Tips
- Flow Shaders
- 3D Rendering
- Custom GPU Passes
- Hot-reload (experimental)
Architecture
Contributing