Function select_word_at

Source
pub fn select_word_at(
    text: &str,
    byte: usize,
    syntax_tokens: Option<&[SyntaxToken]>,
    language: EditorLanguage,
) -> Option<Range<usize>>
Expand description

Selects a syntax token or ASCII lexical word around a UTF-8 byte offset.

A selectable token wins when supplied. The fallback recognizes ASCII Rust raw identifiers and lifetimes, ASCII identifiers in every language, and a fixed set of one-byte punctuation. At or beyond EOF, it examines the final character; empty text and unsupported characters return None.

ยงExamples

use ailloli_ui_editor::{input::selection::select_word_at, EditorLanguage};

assert_eq!(select_word_at("let r#type = 1;", 7, None, EditorLanguage::Rust), Some(4..10));
assert_eq!(select_word_at("abc", usize::MAX, None, EditorLanguage::PlainText), Some(0..3));
assert_eq!(select_word_at(" ", 0, None, EditorLanguage::PlainText), None);