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') }"> <button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike strike
</button> </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 code
</button> </button>
<button @click="editor.chain().focus().removeMarks().run()"> <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') }"> <button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike strike
</button> </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 code
</button> </button>
<button @click="editor.chain().focus().removeMarks().run()"> <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') }"> <button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike strike
</button> </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 code
</button> </button>
<button @click="editor.chain().focus().removeMarks().run()"> <button @click="editor.chain().focus().removeMarks().run()">

View File

@@ -1,6 +1,6 @@
<template> <template>
<div v-if="editor"> <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 code
</button> </button>

View File

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