mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 22:36:14 +08:00
add shortform to keys
This commit is contained in:
parent
f29b39238b
commit
e03d108423
@ -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 {}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -42,9 +42,7 @@ export default class Bold extends Mark {
|
||||
}
|
||||
|
||||
keys() {
|
||||
return {
|
||||
'Mod-b': () => this.editor.bold(),
|
||||
}
|
||||
return 'Mod-b'
|
||||
}
|
||||
|
||||
inputRules() {
|
||||
|
@ -33,9 +33,7 @@ export default class Code extends Mark {
|
||||
}
|
||||
|
||||
keys() {
|
||||
return {
|
||||
'Mod-`': () => this.editor.code(),
|
||||
}
|
||||
return 'Mod-`'
|
||||
}
|
||||
|
||||
inputRules() {
|
||||
|
@ -34,9 +34,7 @@ export default class Italic extends Mark {
|
||||
}
|
||||
|
||||
keys() {
|
||||
return {
|
||||
'Mod-i': () => this.editor.italic(),
|
||||
}
|
||||
return 'Mod-i'
|
||||
}
|
||||
|
||||
inputRules() {
|
||||
|
Loading…
Reference in New Issue
Block a user