diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index da45fa441..6b22e0436 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -1,4 +1,4 @@ -import { Editor } from './Editor' +import { Editor, Command } from './Editor' export default abstract class Extension { @@ -39,11 +39,11 @@ export default abstract class Extension { return [] } - keys(): { [key: string]: any } { + keys(): string | { [key: string]: Function } { return {} } - commands(): { [key: string]: any } { + commands(): { [key: string]: Command } { return {} } diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 9b81746fd..0e7645cc7 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -79,7 +79,17 @@ export default class ExtensionManager { get keymaps() { return collect(this.extensions) - .map(extension => extension.keys()) + .map(extension => { + const keys = extension.keys() + + if (typeof keys === 'string') { + return { + [keys]: () => this.editor.command(extension.name) + } + } + + return keys + }) .filter(keys => !!Object.keys(keys).length) .map(keys => keymap(keys)) .toArray() diff --git a/packages/extension-bold/index.ts b/packages/extension-bold/index.ts index e40a20db5..349a9c2e8 100644 --- a/packages/extension-bold/index.ts +++ b/packages/extension-bold/index.ts @@ -42,9 +42,7 @@ export default class Bold extends Mark { } keys() { - return { - 'Mod-b': () => this.editor.bold(), - } + return 'Mod-b' } inputRules() { diff --git a/packages/extension-code/index.ts b/packages/extension-code/index.ts index f2e2b386f..b93750077 100644 --- a/packages/extension-code/index.ts +++ b/packages/extension-code/index.ts @@ -33,9 +33,7 @@ export default class Code extends Mark { } keys() { - return { - 'Mod-`': () => this.editor.code(), - } + return 'Mod-`' } inputRules() { diff --git a/packages/extension-italic/index.ts b/packages/extension-italic/index.ts index 058867fba..4bedfb58d 100644 --- a/packages/extension-italic/index.ts +++ b/packages/extension-italic/index.ts @@ -34,9 +34,7 @@ export default class Italic extends Mark { } keys() { - return { - 'Mod-i': () => this.editor.italic(), - } + return 'Mod-i' } inputRules() {