revert some magic

This commit is contained in:
Philipp Kühn 2020-04-13 12:27:29 +02:00
parent e03d108423
commit ca16a31e75
5 changed files with 80 additions and 90 deletions

View File

@ -39,7 +39,7 @@ export default abstract class Extension {
return []
}
keys(): string | { [key: string]: Function } {
keys(): { [key: string]: Function } {
return {}
}

View File

@ -79,17 +79,7 @@ export default class ExtensionManager {
get keymaps() {
return collect(this.extensions)
.map(extension => {
const keys = extension.keys()
if (typeof keys === 'string') {
return {
[keys]: () => this.editor.command(extension.name)
}
}
return keys
})
.map(extension => extension.keys())
.filter(keys => !!Object.keys(keys).length)
.map(keys => keymap(keys))
.toArray()

View File

@ -42,41 +42,41 @@ export default class Bold extends Mark {
}
keys() {
return 'Mod-b'
return {
'Mod-b': () => this.editor.bold()
}
}
inputRules() {
return ['**', '__'].map(character => {
return markInputRule(
VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.type,
)
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine()
return markInputRule(regex, this.type)
})
}
pasteRules() {
return ['**', '__'].map(character => {
return markPasteRule(
VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.type,
)
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
return markPasteRule(regex, this.type)
})
}

View File

@ -33,38 +33,38 @@ export default class Code extends Mark {
}
keys() {
return 'Mod-`'
return {
'Mod-`': () => this.editor.code()
}
}
inputRules() {
return markInputRule(
VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find('`')
.beginCapture()
.somethingBut('`')
.endCapture()
.find('`')
.endCapture()
.endOfLine(),
this.type,
)
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find('`')
.beginCapture()
.somethingBut('`')
.endCapture()
.find('`')
.endCapture()
.endOfLine()
return markInputRule(regex, this.type)
}
pasteRules() {
return markPasteRule(
VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find('`')
.beginCapture()
.somethingBut('`')
.endCapture()
.find('`')
.endCapture(),
this.type,
)
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find('`')
.beginCapture()
.somethingBut('`')
.endCapture()
.find('`')
.endCapture()
return markPasteRule(regex, this.type)
}
}

View File

@ -34,41 +34,41 @@ export default class Italic extends Mark {
}
keys() {
return 'Mod-i'
return {
'Mod-i': () => this.editor.italic()
}
}
inputRules() {
return ['*', '_'].map(character => {
return markInputRule(
VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.type,
)
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine()
return markInputRule(regex, this.type)
})
}
pasteRules() {
return ['*', '_'].map(character => {
return markPasteRule(
VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.type,
)
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
return markPasteRule(regex, this.type)
})
}