mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
Fix NodePos logic for child position calculation and attribute changes (#5716)
* fix( nodepos child offsets when child is a non-text atom * fix nodepos attribute update when node is not text * added changesets
This commit is contained in:
parent
0c2b2d100d
commit
d96f679585
5
.changeset/nervous-bats-film.md
Normal file
5
.changeset/nervous-bats-film.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": patch
|
||||
---
|
||||
|
||||
Fixed an issue while updating attributes on a NodePos that was not a text
|
5
.changeset/sweet-feet-dream.md
Normal file
5
.changeset/sweet-feet-dream.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": patch
|
||||
---
|
||||
|
||||
Fixed issues with NodePos child positions causing wrong positions when used on non-text atoms
|
@ -135,8 +135,9 @@ export class NodePos {
|
||||
|
||||
this.node.content.forEach((node, offset) => {
|
||||
const isBlock = node.isBlock && !node.isTextblock
|
||||
const isNonTextAtom = node.isAtom && !node.isText
|
||||
|
||||
const targetPos = this.pos + offset + 1
|
||||
const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1)
|
||||
const $pos = this.resolvedPos.doc.resolve(targetPos)
|
||||
|
||||
if (!isBlock && $pos.depth <= this.depth) {
|
||||
@ -235,9 +236,13 @@ export class NodePos {
|
||||
}
|
||||
|
||||
setAttribute(attributes: { [key: string]: any }) {
|
||||
const oldSelection = this.editor.state.selection
|
||||
const { tr } = this.editor.state
|
||||
|
||||
this.editor.chain().setTextSelection(this.from).updateAttributes(this.node.type.name, attributes).setTextSelection(oldSelection.from)
|
||||
.run()
|
||||
tr.setNodeMarkup(this.from, undefined, {
|
||||
...this.node.attrs,
|
||||
...attributes,
|
||||
})
|
||||
|
||||
this.editor.view.dispatch(tr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user