add link commands
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<button @click="addLink" :class="{ 'is-active': editor.isActive('link') }">
|
||||
link
|
||||
</button>
|
||||
<button @click="editor.chain().focus().removeMark('link').run()" v-if="editor.isActive('link')">
|
||||
<button @click="editor.chain().focus().removeLink().run()" v-if="editor.isActive('link')">
|
||||
remove
|
||||
</button>
|
||||
<editor-content :editor="editor" />
|
||||
@@ -55,7 +55,7 @@ export default {
|
||||
addLink() {
|
||||
const url = window.prompt('URL')
|
||||
|
||||
this.editor.chain().focus().link({ href: url }).run()
|
||||
this.editor.chain().focus().addLink({ href: url }).run()
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<button @click="addLink" :class="{ 'is-active': editor.isActive('link') }">
|
||||
link
|
||||
</button>
|
||||
<button @click="editor.chain().focus().removeMark('link').run()" v-if="editor.isActive('link')">
|
||||
<button @click="editor.chain().focus().removeLink().run()" v-if="editor.isActive('link')">
|
||||
remove
|
||||
</button>
|
||||
<editor-content :editor="editor" />
|
||||
@@ -52,7 +52,7 @@ export default {
|
||||
addLink() {
|
||||
const url = window.prompt('URL')
|
||||
|
||||
this.editor.chain().focus().link({ href: url }).run()
|
||||
this.editor.chain().focus().addLink({ href: url }).run()
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -47,14 +47,22 @@ const Link = Mark.create({
|
||||
addCommands() {
|
||||
return {
|
||||
/**
|
||||
* Toggle or update a link mark
|
||||
* Add a link mark
|
||||
*/
|
||||
link: (options: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||
if (!options.href) {
|
||||
addLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||
return commands.addMark('link', attributes)
|
||||
},
|
||||
/**
|
||||
* Toggle a link mark
|
||||
*/
|
||||
toggleLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||
return commands.toggleMark('link', attributes)
|
||||
},
|
||||
/**
|
||||
* Remove a link mark
|
||||
*/
|
||||
removeLink: (): Command => ({ commands }) => {
|
||||
return commands.removeMark('link')
|
||||
}
|
||||
|
||||
return commands.addMark('link', options)
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user