Two protections make this safe against patterns the user can legitimately
type. A zero-length match (a*, (?:), ^) advances lastIndex by one
manually, without that the loop never terminates. And the total is capped,
so a pattern matching at every position in a large document degrades into a
truncated result rather than freezing the editor while it decorates.
All matches across the document's textblocks.
Two protections make this safe against patterns the user can legitimately type. A zero-length match (
a*,(?:),^) advanceslastIndexby one manually, without that the loop never terminates. And the total is capped, so a pattern matching at every position in a large document degrades into a truncated result rather than freezing the editor while it decorates.