Function styled_spans_for_run

Source
pub fn styled_spans_for_run(
    run: &EditorTextRun,
    tokens: &[SyntaxToken],
    style: EditorStyle,
    theme: CodeTheme,
) -> Vec<StyledTextSpan>
Expand description

Converts source syntax tokens into validated run-local styled spans.

Tokens are clipped to the run, but ranges outside the run text or on invalid UTF-8 boundaries are skipped. Spans whose semantic color equals the base foreground are omitted. Input order and overlaps are preserved for the text system to resolve.

ยงExamples

use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_editor::{code::{SyntaxKind, SyntaxToken}, layout::EditorTextRun, paint::syntax_painter::styled_spans_for_run, CodeTheme, EditorStyle};
use ailloli_ui_text::{TextLayoutParams, TextSystem};
let mut system = TextSystem::new();
let layout = system.layout_cached(TextLayoutParams::new("fn x", TextStyle::new(FontId::Mono, 13, Color::WHITE)));
let run = EditorTextRun { index: 0, byte_range: 10..14, baseline_y: 12.0, layout };
let spans = styled_spans_for_run(&run, &[SyntaxToken { range: 10..12, kind: SyntaxKind::Keyword }], EditorStyle::default(), CodeTheme::default());
assert_eq!(spans[0].range, 0..2);