Skip to main content

Module code

Module code 

Source
Expand description

Code block widget with syntax highlighting

Two modes of operation:

  • Read-only via code("content") — lightweight display widget, no Stateful overhead
  • Editable via code_editor(&state) — full editor with Stateful incremental updates

§Read-only Example

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)

§Editable Example

let state = code_editor_state("let x = 42;");
code_editor(&state)
    .syntax(SyntaxConfig::new(RustHighlighter::new()))
    .line_numbers(true)
    .h(400.0)
    .on_change(|new_content| {
        println!("Content changed: {}", new_content);
    })

§Editor Features

Editing: Type, Enter (auto-indent), Backspace, Delete, Tab/Shift+Tab (indent/dedent), Cmd+Backspace/Delete (delete word), Cmd+Z/Shift+Z (undo/redo)

Navigation: Arrow keys, Cmd+Left/Right (word jump), Home (smart: first non-whitespace then col 0), End, Page Up/Down, mouse click, mouse drag selection, double-click word select

Clipboard: Cmd+A (select all), Cmd+C (copy), Cmd+X (cut), Cmd+V (paste)

Visual: Syntax highlighting (cached per-line), line numbers, selection highlight, current line highlight, cursor with blink animation, vertical scroll (overflow_y_scroll)

Structs§

Code
Read-only code block widget
CodeConfig
Code block configuration
CodeEditor
Editable code editor widget using Stateful for incremental updates
CodeEditorData
Internal state for code editing
FoldRegion
A foldable region detected from bracket matching
UndoEntry
Undo/redo entry

Functions§

code
Create a read-only code block
code_editor
Create an editable code editor widget
code_editor_state
Create a new shared code editor state
code_minimap
Build a minimap — a scaled-down overview of all code lines Build a minimap widget from code editor state. This should be placed as a sibling OUTSIDE the code_editor, not inside it.
pre
Create a preformatted text block (alias for code)

Type Aliases§

SharedCodeEditorState
Shared code editor state (thread-safe, persists across rebuilds)