From 5f54a86da7329410b35da36d609c06971594ded0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 12 Mar 2021 23:52:54 +0100 Subject: [PATCH] fix bug --- .../NodeViews/TableOfContents/Component.vue | 23 ++++++------------- .../Guide/NodeViews/TableOfContents/index.vue | 2 +- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue b/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue index 22ea1f62..07e6e780 100644 --- a/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue +++ b/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue @@ -39,13 +39,15 @@ export default { methods: { handleUpdate() { const headings = [] + const transaction = this.editor.state.tr this.editor.state.doc.descendants((node, pos) => { if (node.type.name === 'heading') { const id = `heading-${headings.length + 1}` if (node.attrs.id !== id) { - this.updateNodeAttributes(node, pos, { + transaction.setNodeMarkup(pos, undefined, { + ...node.attrs, id, }) } @@ -58,28 +60,17 @@ export default { } }) - this.headings = headings - }, - updateNodeAttributes(node, pos, attributes) { - const { state } = this.editor.view - const transaction = state.tr.setNodeMarkup(pos, undefined, { - ...node.attrs, - ...attributes, - }) + transaction.setMeta('preventUpdate', true) - console.log(pos, undefined, { - ...node.attrs, - ...attributes, - }) - - // TODO: Why is that not needed? 🤔 this.editor.view.dispatch(transaction) + + this.headings = headings }, }, mounted() { this.editor.on('update', this.handleUpdate) - this.handleUpdate() + this.$nextTick(this.handleUpdate) }, } diff --git a/docs/src/demos/Guide/NodeViews/TableOfContents/index.vue b/docs/src/demos/Guide/NodeViews/TableOfContents/index.vue index 2b8cb8b4..9db45b5f 100644 --- a/docs/src/demos/Guide/NodeViews/TableOfContents/index.vue +++ b/docs/src/demos/Guide/NodeViews/TableOfContents/index.vue @@ -27,6 +27,7 @@ export default { TableOfContents, ], content: ` +

1 heading

paragraph

1.1 heading

@@ -37,7 +38,6 @@ export default {

paragraph

2.1 heading

paragraph

- `, }) },