Skip to content

Commit

Permalink
Revert Shortcut command for Clear Format on mac (#2834)
Browse files Browse the repository at this point in the history
* revert Shortcut command for Clear Format on mac

* fix ctrl and meta can press in the same time

* update comment
  • Loading branch information
miku1958 authored Nov 6, 2024
1 parent c2051c7 commit 53a7c76
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -80,7 +80,6 @@ export const ShortcutClearFormat: ShortcutCommand = {
which: Keys.SPACE,
},
onClick: editor => clearFormat(editor),
environment: 'nonMac',
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 53a7c76

Please sign in to comment.