From fc53d6f1ccfdf9f8091fa010a40f703895876bfb Mon Sep 17 00:00:00 2001 From: Alex Shen Date: Sat, 18 Feb 2023 15:13:35 -0500 Subject: [PATCH] Fixed combo meter decoration flickering Combo meter flicker BUG This happens because the previous combo decoration is being disposed before the new one is created. This can be fixed simply by disposing the previous decoration only after the new one is created and rendered. --- src/combo/editor-combo-meter.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/combo/editor-combo-meter.ts b/src/combo/editor-combo-meter.ts index 927635d..61abc92 100644 --- a/src/combo/editor-combo-meter.ts +++ b/src/combo/editor-combo-meter.ts @@ -213,15 +213,19 @@ export class EditorComboMeter implements Plugin { } }; - this.comboTimerDecoration?.dispose(); - this.comboTimerDecoration = vscode.window.createTextEditorDecorationType({ + + const newComboTimerDecoration = vscode.window.createTextEditorDecorationType({ // Decorations cannot use the same pseudoelement ...createComboTimerBeforeDecoration(), rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, light: createComboTimerBeforeDecoration(true), }); - editor.setDecorations(this.comboTimerDecoration, ranges); + editor.setDecorations(newComboTimerDecoration, ranges); + + this.comboTimerDecoration?.dispose(); + + this.comboTimerDecoration = newComboTimerDecoration; } this.comboTimerDecorationTimer = setInterval(updateComboTimerDecoration, this.TIMER_UPDATE_INTERVAL); @@ -235,7 +239,6 @@ export class EditorComboMeter implements Plugin { } const animateComboCountDecoration = (frameCount: number) => { - this.comboCountDecoration?.dispose(); const { textSize, color } = this.getSharedStyles(count, frameCount); @@ -261,14 +264,18 @@ export class EditorComboMeter implements Plugin { }; } - this.comboCountDecoration = vscode.window.createTextEditorDecorationType({ + const newComboCountDecoration = vscode.window.createTextEditorDecorationType({ // Note: Different decorations cannot use the same pseudoelement ...createComboCountAfterDecoration(), rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, light: createComboCountAfterDecoration(true), }); - editor.setDecorations(this.comboCountDecoration, ranges); + editor.setDecorations(newComboCountDecoration, ranges); + + this.comboCountDecoration?.dispose(); + + this.comboCountDecoration = newComboCountDecoration; // Only animate in power mode if (this.isPowermodeActive && frameCount < 100) { @@ -294,4 +301,4 @@ export class EditorComboMeter implements Plugin { return cssString; } -} \ No newline at end of file +}