irongit

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

fixed duplicating issue

huncholanehuncholaneauthored
parent 34f6d99commit 7b11bf31d28c404ce2537e889fb1c95bc86a377eBrowse files

1 file changed, +16 -12

+16-12src/highlighter.ts
@@ -12,7 +12,6 @@ type HighlightGroup = {
1212
1313 class Highlighter {
1414 context: vscode.ExtensionContext | undefined;
15- decorations: vscode.TextEditorDecorationType[] = [];
1615 highlightGroups: { [key: string]: HighlightGroup } = {};
1716
1817 constructor() {}
@@ -22,15 +21,20 @@ class Highlighter {
2221 this.context = context;
2322 }
2423
24+ getDecorationTypes() {
25+ return Object.values(this.highlightGroups).map(
26+ (group) => group.decorationType
27+ );
28+ }
29+
2530 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}`);
2834 decoration.dispose();
2935 });
3036 this.highlightGroups = {};
31- this.decorations = [];
3237 decorationGenerator.reset();
33- output.clear();
3438 }
3539
3640 clearRanges() {
@@ -44,15 +48,15 @@ class Highlighter {
4448 range: vscode.Range,
4549 options: vscode.DecorationRenderOptions = {}
4650 ) {
51+ const decoration = { range, hoverMessage: key };
52+ output.log(`Highlighting ${key}`);
53+ const decorationType = decorationGenerator.generate(options);
4754 if (this.highlightGroups[key]) {
48- this.highlightGroups[key].decorations.push({
49- range,
50- hoverMessage: key,
51- });
55+ this.highlightGroups[key].decorations.push(decoration);
5256 } else {
5357 this.highlightGroups[key] = {
54- decorations: [{ range, hoverMessage: key }],
55- decorationType: decorationGenerator.generate(options),
58+ decorations: [decoration],
59+ decorationType: decorationType,
5660 };
5761 }
5862 }
@@ -87,7 +91,7 @@ class Highlighter {
8791 const end = document.positionAt(match.index + match[0].length);
8892 this.updateOrCreateHighlightGroup("outer", new vscode.Range(start, end));
8993 for (const groupName in match.groups) {
90- output.log(`Match: ${groupName}`);
94+ // output.log(`Match: ${groupName}`);
9195 const group = match.groups[groupName];
9296 const start = document.positionAt(
9397 match.index + match[0].indexOf(group)