mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-22 16:10:50 +00:00
* improve terminal keyword highlight refresh * fix(terminal): address Codex review on keyword highlight refresh Map viewport probe diffs to line numbers so off-cursor ANSI redraws mark the rewritten line dirty without forcing full-viewport rescans on normal typing, and cache wrapped-line context per processLineRange to avoid repeated scans. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: mam15mon <mam15mon@gmail.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
654 B
TypeScript
25 lines
654 B
TypeScript
export function forEachNonEmptyRegexMatch(
|
|
regex: RegExp,
|
|
text: string,
|
|
onMatch: (match: RegExpExecArray) => void,
|
|
) {
|
|
regex.lastIndex = 0;
|
|
|
|
let match: RegExpExecArray | null;
|
|
while ((match = regex.exec(text)) !== null) {
|
|
if (match[0].length === 0) {
|
|
if (regex.lastIndex <= match.index) {
|
|
// Advance past the full code point to avoid landing inside a surrogate pair
|
|
const code = text.charCodeAt(match.index);
|
|
regex.lastIndex = match.index + (code >= 0xD800 && code <= 0xDBFF ? 2 : 1);
|
|
}
|
|
if (regex.lastIndex > text.length) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
onMatch(match);
|
|
}
|
|
}
|