From 2032ffb48037a05060bcf2a927cb74cb1ece0bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Fri, 18 Oct 2024 10:55:36 +0800 Subject: [PATCH 1/3] revert Shortcut command for Clear Format on mac --- .../lib/shortcut/shortcuts.ts | 3 +-- .../test/shortcut/ShortcutPluginTest.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts b/packages/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts index ffb004af755..ed1831e02d5 100644 --- a/packages/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts +++ b/packages/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts @@ -71,7 +71,7 @@ export const ShortcutUnderline: ShortcutCommand = { /** * Shortcut command for Clear Format * Windows: Ctrl + Space - * MacOS: N/A + * MacOS: Meta + Space, this shortcut is the same as the default global spotlight shortcut, so it is invalid if the user keeps spotlight‘s. */ export const ShortcutClearFormat: ShortcutCommand = { shortcutKey: { @@ -80,7 +80,6 @@ export const ShortcutClearFormat: ShortcutCommand = { which: Keys.SPACE, }, onClick: editor => clearFormat(editor), - environment: 'nonMac', }; /** diff --git a/packages/roosterjs-content-model-plugins/test/shortcut/ShortcutPluginTest.ts b/packages/roosterjs-content-model-plugins/test/shortcut/ShortcutPluginTest.ts index bcb173ed278..f863627e71c 100644 --- a/packages/roosterjs-content-model-plugins/test/shortcut/ShortcutPluginTest.ts +++ b/packages/roosterjs-content-model-plugins/test/shortcut/ShortcutPluginTest.ts @@ -448,6 +448,26 @@ describe('ShortcutPlugin', () => { expect(apiSpy).toHaveBeenCalledWith(mockedEditor); }); + it('clear format', () => { + const apiSpy = spyOn(clearFormat, 'clearFormat'); + const plugin = new ShortcutPlugin(); + const event: PluginEvent = { + eventType: 'keyDown', + rawEvent: createMockedEvent(Keys.SPACE, false, false, false, true), + }; + + plugin.initialize(mockedEditor); + + const exclusively = plugin.willHandleEventExclusively(event); + + expect(exclusively).toBeTrue(); + expect(event.eventDataCache!.__ShortcutCommandCache).toBeDefined(); + + plugin.onPluginEvent(event); + + expect(apiSpy).toHaveBeenCalledWith(mockedEditor); + }); + it('undo 1', () => { const apiSpy = spyOn(undo, 'undo'); const plugin = new ShortcutPlugin(); From 99c0e67ce3aa0c8ee9d11fbfbdb04f389498de4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Tue, 5 Nov 2024 13:19:30 +0800 Subject: [PATCH 2/3] fix ctrl and meta can press in the same time --- .../lib/shortcut/ShortcutPlugin.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts b/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts index 96987379992..5b0015089bd 100644 --- a/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts @@ -119,7 +119,11 @@ export class ShortcutPlugin implements EditorPlugin { private cacheGetCommand(event: KeyDownEvent) { return cacheGetEventData(event, CommandCacheKey, event => { const editor = this.editor; - + const { ctrlKey, metaKey } = event.rawEvent; + if (ctrlKey && metaKey) { + // We don't support both Ctrl and Meta key pressed at the same time + return null; + } return ( editor && this.shortcuts.filter( From 839a2480cd617525a81fbcd3553917d942f03c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=BB=9B=E6=B7=B3=E5=8D=8E?= Date: Wed, 6 Nov 2024 14:22:40 +0800 Subject: [PATCH 3/3] update comment --- .../lib/shortcut/ShortcutPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts b/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts index 5b0015089bd..b8d23493fab 100644 --- a/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts @@ -121,7 +121,7 @@ export class ShortcutPlugin implements EditorPlugin { const editor = this.editor; const { ctrlKey, metaKey } = event.rawEvent; if (ctrlKey && metaKey) { - // We don't support both Ctrl and Meta key pressed at the same time + // We don't support both Ctrl and Meta key pressed at the same time. return null; } return (