A Regex file extension that makes it way easier to edit large regex.
fixed duplicating issue
1 file changed, +16 -12
+16-12src/highlighter.ts
| @@ -12,7 +12,6 @@ type HighlightGroup = { | ||
| 12 | 12 | |
| 13 | 13 | class Highlighter { |
| 14 | 14 | context: vscode.ExtensionContext | undefined; |
| 15 | - decorations: vscode.TextEditorDecorationType[] = []; | |
| 16 | 15 | highlightGroups: { [key: string]: HighlightGroup } = {}; |
| 17 | 16 | |
| 18 | 17 | constructor() {} |
| @@ -22,15 +21,20 @@ class Highlighter { | ||
| 22 | 21 | this.context = context; |
| 23 | 22 | } |
| 24 | 23 | |
| 24 | + getDecorationTypes() { | |
| 25 | + return Object.values(this.highlightGroups).map( | |
| 26 | + (group) => group.decorationType | |
| 27 | + ); | |
| 28 | + } | |
| 29 | + | |
| 25 | 30 | reset() { |
| 26 | - // output.log("Resetting decorations"); | |
| 27 | - this.decorations.forEach((decoration) => { | |
| 31 | + output.clear(); | |
| 32 | + this.getDecorationTypes().forEach((decoration) => { | |
| 33 | + output.log(`Disposing decoration: ${decoration.key}`); | |
| 28 | 34 | decoration.dispose(); |
| 29 | 35 | }); |
| 30 | 36 | this.highlightGroups = {}; |
| 31 | - this.decorations = []; | |
| 32 | 37 | decorationGenerator.reset(); |
| 33 | - output.clear(); | |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | 40 | clearRanges() { |
| @@ -44,15 +48,15 @@ class Highlighter { | ||
| 44 | 48 | range: vscode.Range, |
| 45 | 49 | options: vscode.DecorationRenderOptions = {} |
| 46 | 50 | ) { |
| 51 | + const decoration = { range, hoverMessage: key }; | |
| 52 | + output.log(`Highlighting ${key}`); | |
| 53 | + const decorationType = decorationGenerator.generate(options); | |
| 47 | 54 | if (this.highlightGroups[key]) { |
| 48 | - this.highlightGroups[key].decorations.push({ | |
| 49 | - range, | |
| 50 | - hoverMessage: key, | |
| 51 | - }); | |
| 55 | + this.highlightGroups[key].decorations.push(decoration); | |
| 52 | 56 | } else { |
| 53 | 57 | this.highlightGroups[key] = { |
| 54 | - decorations: [{ range, hoverMessage: key }], | |
| 55 | - decorationType: decorationGenerator.generate(options), | |
| 58 | + decorations: [decoration], | |
| 59 | + decorationType: decorationType, | |
| 56 | 60 | }; |
| 57 | 61 | } |
| 58 | 62 | } |
| @@ -87,7 +91,7 @@ class Highlighter { | ||
| 87 | 91 | const end = document.positionAt(match.index + match[0].length); |
| 88 | 92 | this.updateOrCreateHighlightGroup("outer", new vscode.Range(start, end)); |
| 89 | 93 | for (const groupName in match.groups) { |
| 90 | - output.log(`Match: ${groupName}`); | |
| 94 | + // output.log(`Match: ${groupName}`); | |
| 91 | 95 | const group = match.groups[groupName]; |
| 92 | 96 | const start = document.positionAt( |
| 93 | 97 | match.index + match[0].indexOf(group) |