mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
use insertContent in some extensions
This commit is contained in:
parent
12b6f0e4f7
commit
fda4c780d3
@ -42,28 +42,31 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setHorizontalRule: () => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
tr.replaceSelectionWith(this.type.create())
|
||||
setHorizontalRule: () => ({ chain }) => {
|
||||
return chain()
|
||||
.insertContent({ type: this.name })
|
||||
.command(({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
const { parent, pos } = tr.selection.$from
|
||||
const posAfter = pos + 1
|
||||
const nodeAfter = tr.doc.nodeAt(posAfter)
|
||||
|
||||
const { parent, pos } = tr.selection.$from
|
||||
const posAfter = pos + 1
|
||||
const nodeAfter = tr.doc.nodeAt(posAfter)
|
||||
// end of document
|
||||
if (!nodeAfter) {
|
||||
const node = parent.type.contentMatch.defaultType?.create()
|
||||
|
||||
// end of document
|
||||
if (!nodeAfter) {
|
||||
const node = parent.type.contentMatch.defaultType?.create()
|
||||
if (node) {
|
||||
tr.insert(posAfter, node)
|
||||
tr.setSelection(TextSelection.create(tr.doc, posAfter))
|
||||
}
|
||||
}
|
||||
|
||||
if (node) {
|
||||
tr.insert(posAfter, node)
|
||||
tr.setSelection(TextSelection.create(tr.doc, posAfter))
|
||||
tr.scrollIntoView()
|
||||
}
|
||||
}
|
||||
|
||||
tr.scrollIntoView()
|
||||
}
|
||||
|
||||
return true
|
||||
return true
|
||||
})
|
||||
.run()
|
||||
},
|
||||
}
|
||||
},
|
||||
|
@ -69,15 +69,11 @@ export const Image = Node.create<ImageOptions>({
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setImage: options => ({ tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const node = this.type.create(options)
|
||||
|
||||
if (dispatch) {
|
||||
tr.replaceRangeWith(selection.from, selection.to, node)
|
||||
}
|
||||
|
||||
return true
|
||||
setImage: options => ({ commands }) => {
|
||||
return commands.insertContent({
|
||||
type: this.name,
|
||||
attrs: options,
|
||||
})
|
||||
},
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user