irongit

A Regex file extension that makes it way easier to edit large regex.

added timeout

huncholanehuncholaneauthored
parent 6a24297commit 0a8b4e0ebebdb630689f9859395dce65d15ff933Browse files

1 file changed, +4 -2

+4-2src/highlighter.ts
@@ -66,6 +66,8 @@ class Highlighter {
6666
6767 matchOnEditor(regex: string, document: vscode.TextDocument) {
6868 const flags = regexButtons.getFlagString();
69+ const timeout = getConfig().get("timeout") as number;
70+ const startTime = Date.now();
6971 if (regexButtons.hasXFlag()) {
7072 regex = this.applyXFlag(regex);
7173 }
@@ -80,7 +82,7 @@ class Highlighter {
8082 let i = 0;
8183 const maxMatches = getConfig().get("maxMatches") as number;
8284 for (const match of matches) {
83- if (i >= maxMatches) {
85+ if (i >= maxMatches || Date.now() - startTime > timeout) {
8486 break;
8587 }
8688 if (match.index === undefined) {
@@ -111,7 +113,7 @@ class Highlighter {
111113 }
112114
113115 matchRegexGroups(document: vscode.TextDocument) {
114- const re = /(?<=\<).+?(?=\>)/g;
116+ const re = /(?<=\().+?(?=\))/g;
115117 const matches = document.getText().matchAll(re);
116118 let i = 0;
117119 const maxMatches = getConfig().get("maxMatches") as number;