mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
add image command
This commit is contained in:
parent
9a376a66e6
commit
e526c788c9
@ -31,7 +31,7 @@ export default {
|
||||
addImage() {
|
||||
const url = window.prompt('URL')
|
||||
|
||||
this.editor.chain().focus().image({ src: url }).run()
|
||||
this.editor.chain().focus().setImage({ src: url }).run()
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -58,11 +58,13 @@ const Image = Node.create({
|
||||
/**
|
||||
* Add an image
|
||||
*/
|
||||
image: (options: { src: string, alt?: string, title?: string }): Command => ({ tr }) => {
|
||||
setImage: (options: { src: string, alt?: string, title?: string }): Command => ({ tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const node = this.type.create(options)
|
||||
|
||||
tr.replaceRangeWith(selection.from, selection.to, node)
|
||||
if (dispatch) {
|
||||
tr.replaceRangeWith(selection.from, selection.to, node)
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user