Files
Netcatty/components/terminal/keywordHighlightRegex.test.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

39 lines
1019 B
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { forEachNonEmptyRegexMatch } from "./keywordHighlightRegex.ts";
test("forEachNonEmptyRegexMatch returns normal consuming matches", () => {
const regex = /\bfoo\b/gi;
const indices: number[] = [];
forEachNonEmptyRegexMatch(regex, "foo bar foo", (match) => {
indices.push(match.index);
});
assert.deepEqual(indices, [0, 8]);
});
test("forEachNonEmptyRegexMatch skips zero-width matches without looping forever", () => {
const regex = /(?=foo)/g;
const indices: number[] = [];
forEachNonEmptyRegexMatch(regex, "foo foo", (match) => {
indices.push(match.index);
});
assert.deepEqual(indices, []);
});
test("forEachNonEmptyRegexMatch resets reused regex state before scanning", () => {
const regex = /\d+/g;
const indices: number[] = [];
regex.lastIndex = 99;
forEachNonEmptyRegexMatch(regex, "1 22 333", (match) => {
indices.push(match.index);
});
assert.deepEqual(indices, [0, 2, 5]);
});