add code commands

This commit is contained in:
Philipp Kühn
2020-11-17 21:53:39 +01:00
parent 8195cbd91d
commit f9025775ca
5 changed files with 18 additions and 6 deletions

View File

@@ -10,7 +10,7 @@
<button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike
</button>
<button @click="editor.chain().focus().code().run()" :class="{ 'is-active': editor.isActive('code') }">
<button @click="editor.chain().focus().toggleCode().run()" :class="{ 'is-active': editor.isActive('code') }">
code
</button>
<button @click="editor.chain().focus().removeMarks().run()">

View File

@@ -10,7 +10,7 @@
<button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike
</button>
<button @click="editor.chain().focus().code().run()" :class="{ 'is-active': editor.isActive('code') }">
<button @click="editor.chain().focus().toggleCode().run()" :class="{ 'is-active': editor.isActive('code') }">
code
</button>
<button @click="editor.chain().focus().removeMarks().run()">

View File

@@ -10,7 +10,7 @@
<button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike
</button>
<button @click="editor.chain().focus().code().run()" :class="{ 'is-active': editor.isActive('code') }">
<button @click="editor.chain().focus().toggleCode().run()" :class="{ 'is-active': editor.isActive('code') }">
code
</button>
<button @click="editor.chain().focus().removeMarks().run()">

View File

@@ -1,6 +1,6 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().code().run()" :class="{ 'is-active': editor.isActive('code') }">
<button @click="editor.chain().focus().toggleCode().run()" :class="{ 'is-active': editor.isActive('code') }">
code
</button>

View File

@@ -35,18 +35,30 @@ const Code = Mark.create({
addCommands() {
return {
/**
* Set a code mark
*/
setCode: (): Command => ({ commands }) => {
return commands.addMark('code')
},
/**
* Toggle inline code
*/
code: (): Command => ({ commands }) => {
toggleCode: (): Command => ({ commands }) => {
return commands.toggleMark('code')
},
/**
* Set a code mark
*/
unsetCode: (): Command => ({ commands }) => {
return commands.addMark('code')
},
}
},
addKeyboardShortcuts() {
return {
'Mod-`': () => this.editor.commands.code(),
'Mod-`': () => this.editor.commands.toggleCode(),
}
},