Function select_token_at

Source
pub fn select_token_at(
    byte: usize,
    syntax_tokens: &[SyntaxToken],
) -> Option<Range<usize>>
Expand description

Returns the first selectable syntax-token range containing byte.

Containment is half-open. Keyword, type, function, number, operator, punctuation, and identifier tokens are selectable; string and comment tokens are skipped. Token ranges are returned as supplied without clamping or overlap resolution.

ยงExamples

use ailloli_ui_editor::{input::selection::select_token_at, code::{SyntaxKind, SyntaxToken}};

let tokens = [
    SyntaxToken { range: 0..3, kind: SyntaxKind::Comment },
    SyntaxToken { range: 4..7, kind: SyntaxKind::Identifier },
];
assert_eq!(select_token_at(5, &tokens), Some(4..7));
assert_eq!(select_token_at(3, &tokens), None);