add shortform to keys

This commit is contained in:
Philipp Kühn 2020-04-13 00:16:12 +02:00
parent f29b39238b
commit e03d108423
5 changed files with 17 additions and 13 deletions

View File

@ -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 {}
}

View File

@ -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()

View File

@ -42,9 +42,7 @@ export default class Bold extends Mark {
}
keys() {
return {
'Mod-b': () => this.editor.bold(),
}
return 'Mod-b'
}
inputRules() {

View File

@ -33,9 +33,7 @@ export default class Code extends Mark {
}
keys() {
return {
'Mod-`': () => this.editor.code(),
}
return 'Mod-`'
}
inputRules() {

View File

@ -34,9 +34,7 @@ export default class Italic extends Mark {
}
keys() {
return {
'Mod-i': () => this.editor.italic(),
}
return 'Mod-i'
}
inputRules() {