Files
Netcatty/components/terminal/keywordHighlightRegex.ts
T
278f528deb Improve terminal keyword highlight refresh (#1619)
* 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>
2026-06-24 14:16:16 +08:00

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);
}
}