From 9a10cd4becb834fc46e34a826a94d7249a08d58b Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Mon, 4 Mar 2024 02:34:33 -0800 Subject: [PATCH] Desktop: Fixes #10023: Beta editor plugins: Fix opening and closing settings can break some plugins with legacy code (#10024) --- .../CodeMirror5Emulation.test.ts | 18 ++++++++++++++++++ .../CodeMirror5Emulation.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.test.ts b/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.test.ts index c5ab4609a..c6809efde 100644 --- a/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.test.ts +++ b/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.test.ts @@ -108,4 +108,22 @@ describe('CodeMirror5Emulation', () => { // additional times if its option hasn't updated. expect(onOtherOptionUpdate).toHaveBeenCalledTimes(1); }); + + it('defineExtension should override previous extensions with the same name', () => { + const codeMirror = makeCodeMirrorEmulation('Test...'); + const testExtensionFn1 = jest.fn(); + const testExtensionFn2 = jest.fn(); + + codeMirror.defineExtension('defineExtensionShouldOverride', testExtensionFn1); + + (codeMirror as any).defineExtensionShouldOverride(); + expect(testExtensionFn1).toHaveBeenCalledTimes(1); + expect(testExtensionFn2).toHaveBeenCalledTimes(0); + + codeMirror.defineExtension('defineExtensionShouldOverride', testExtensionFn2); + + (codeMirror as any).defineExtensionShouldOverride(); + expect(testExtensionFn1).toHaveBeenCalledTimes(1); + expect(testExtensionFn2).toHaveBeenCalledTimes(1); + }); }); diff --git a/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts b/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts index 2293c142b..beda4f8ba 100644 --- a/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts +++ b/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts @@ -272,7 +272,7 @@ export default class CodeMirror5Emulation extends BaseCodeMirror5Emulation { } public defineExtension(name: string, value: any) { - (CodeMirror5Emulation.prototype as any)[name] ??= value; + (CodeMirror5Emulation.prototype as any)[name] = value; } public defineOption(name: string, defaultValue: any, onUpdate: OptionUpdateCallback) {