Components / CodeEditor

CodeEditor

Source code with line numbers, colors by language, indenting keys and problems marked on their lines.

Example

The component itself, running in WebAssembly, beside its code in a playground. Try it.

Code

use ravenrs::prelude::*;

fn code_editor() -> impl View {
    let code = State::new(
        "fn total(prices: &[f64]) -> f64 {\n    // Sum of every price\n    prices.iter().sum()\n}\n"
            .to_owned(),
    );
    CodeEditor::new(code.binding())
        .diagnostics(vec![
            CodeDiagnostic::warning(3, 5, 6, "`prices` could be empty").hint("Return 0.0 first"),
        ])
        .rows(10)
}

Open in the playground, with every example →

Full API of CodeEditor →