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 { export default abstract class Extension {
@ -39,11 +39,11 @@ export default abstract class Extension {
return [] return []
} }
keys(): { [key: string]: any } { keys(): string | { [key: string]: Function } {
return {} return {}
} }
commands(): { [key: string]: any } { commands(): { [key: string]: Command } {
return {} return {}
} }

View File

@ -79,7 +79,17 @@ export default class ExtensionManager {
get keymaps() { get keymaps() {
return collect(this.extensions) 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) .filter(keys => !!Object.keys(keys).length)
.map(keys => keymap(keys)) .map(keys => keymap(keys))
.toArray() .toArray()

View File

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

View File

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

View File

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