A Regex file extension that makes it way easier to edit large regex.
added timeout
1 file changed, +4 -2
+4-2src/highlighter.ts
| @@ -66,6 +66,8 @@ class Highlighter { | ||
| 66 | 66 | |
| 67 | 67 | matchOnEditor(regex: string, document: vscode.TextDocument) { |
| 68 | 68 | const flags = regexButtons.getFlagString(); |
| 69 | + const timeout = getConfig().get("timeout") as number; | |
| 70 | + const startTime = Date.now(); | |
| 69 | 71 | if (regexButtons.hasXFlag()) { |
| 70 | 72 | regex = this.applyXFlag(regex); |
| 71 | 73 | } |
| @@ -80,7 +82,7 @@ class Highlighter { | ||
| 80 | 82 | let i = 0; |
| 81 | 83 | const maxMatches = getConfig().get("maxMatches") as number; |
| 82 | 84 | for (const match of matches) { |
| 83 | - if (i >= maxMatches) { | |
| 85 | + if (i >= maxMatches || Date.now() - startTime > timeout) { | |
| 84 | 86 | break; |
| 85 | 87 | } |
| 86 | 88 | if (match.index === undefined) { |
| @@ -111,7 +113,7 @@ class Highlighter { | ||
| 111 | 113 | } |
| 112 | 114 | |
| 113 | 115 | matchRegexGroups(document: vscode.TextDocument) { |
| 114 | - const re = /(?<=\<).+?(?=\>)/g; | |
| 116 | + const re = /(?<=\().+?(?=\))/g; | |
| 115 | 117 | const matches = document.getText().matchAll(re); |
| 116 | 118 | let i = 0; |
| 117 | 119 | const maxMatches = getConfig().get("maxMatches") as number; |