irongit

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

forcestop boolean makes it very smooth

huncholanehuncholaneauthored
parent 0a8b4e0commit 25f7bf79786192b87c2c8b9fe91d2bc163842c97Browse files

2 files changed, +14 -9

+5-8src/extension.ts
@@ -11,17 +11,14 @@ export function activate(context: vscode.ExtensionContext) {
1111
1212 vscode.window.onDidChangeActiveTextEditor((editor) => {
1313 if (editor && editor.document.uri.scheme === "file") {
14- if (editor.document.languageId === "regex") {
15- // output.log("Regex file opened");
16- regexButtons.show();
14+ if (editorsContainRegexFile()) {
1715 highlighter.run();
16+ regexButtons.show();
17+ } else {
18+ highlighter.reset();
19+ regexButtons.hide();
1820 }
1921 }
20- if (!editorsContainRegexFile()) {
21- highlighter.reset();
22- regexButtons.hide();
23- output.log("No regex file opened");
24- }
2522 });
2623
2724 vscode.workspace.onDidChangeTextDocument((event) => {
+9-1src/highlighter.ts
@@ -13,6 +13,7 @@ type HighlightGroup = {
1313 class Highlighter {
1414 context: vscode.ExtensionContext | undefined;
1515 highlightGroups: { [key: string]: HighlightGroup } = {};
16+ forceStop = false;
1617
1718 constructor() {}
1819
@@ -65,6 +66,7 @@ class Highlighter {
6566 }
6667
6768 matchOnEditor(regex: string, document: vscode.TextDocument) {
69+ this.forceStop = false;
6870 const flags = regexButtons.getFlagString();
6971 const timeout = getConfig().get("timeout") as number;
7072 const startTime = Date.now();
@@ -82,7 +84,12 @@ class Highlighter {
8284 let i = 0;
8385 const maxMatches = getConfig().get("maxMatches") as number;
8486 for (const match of matches) {
85- if (i >= maxMatches || Date.now() - startTime > timeout) {
87+ if (
88+ i >= maxMatches ||
89+ Date.now() - startTime > timeout ||
90+ this.forceStop
91+ ) {
92+ this.forceStop = false;
8693 break;
8794 }
8895 if (match.index === undefined) {
@@ -148,6 +155,7 @@ class Highlighter {
148155 this.highlightMatches(regexEditor);
149156 this.clearRanges();
150157 const nonRegexEditors = getNonRegexEditors();
158+ output.log(`Highlighting ${nonRegexEditors.length} editors`);
151159 for (const editor of nonRegexEditors) {
152160 this.matchOnEditor(regexEditor.document.getText(), editor.document);
153161 this.highlightMatches(editor);