M2.2: PHP highlighting, syntax colour tokens and editor.reveal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-17 12:06:42 +02:00
parent f13a49064d
commit 6c75c08d70
25 changed files with 1044 additions and 33 deletions

View file

@ -212,3 +212,25 @@ export function diffDocs(from: Text, to: Text): ChangeSet {
a.length,
);
}
/**
* The CodeMirror position of an engine `{line, column}` position.
*
* Engine lines are split at the same breaks CodeMirror recognises, and a
* `\r\n` counts as one break on both sides, so line numbers carry over
* unchanged; the column counts UTF-16 code units inside the line, which is
* the same in both. A line past the end selects the last line, a column past
* the line's end (into a `\r\n`, say) its end, and negative or fractional
* values are clamped and truncated (non-finite ones count as 0). Converting the result back with
* {@link EngineText.toEngine} yields the engine offset.
*
* @param doc - the CodeMirror document.
* @param line - 0-based line.
* @param column - 0-based column in UTF-16 code units.
* @returns the position in `doc`.
*/
export function positionOf(doc: Text, line: number, column: number): number {
const whole = (n: number): number => (Number.isFinite(n) ? Math.max(Math.trunc(n), 0) : 0);
const target = doc.line(Math.min(whole(line) + 1, doc.lines));
return target.from + Math.min(whole(column), target.length);
}