Skip to main content

detect_context

Function detect_context 

Source
pub fn detect_context(model: &Model<'_>, prefix: &[u16]) -> Option<Mode>
Expand description

Language of the last two words in prefix, the session’s own finished text.

The scan runs back over at most the last 256 UTF-16 units, skips non-letters and gives up at LF or CR. It returns a language only when the last two letter runs are both words of the same language’s lexicon; fewer than two runs, a mixed-script run, a word the lexicon lacks or a run cut by the 256-unit window gives None. This consumes supplied context, never reads a document, and does not define automatic token eligibility or authorize a replacement range.