From fce6d9dac90323ac8787f096713c71fcfd3ab9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 31 Jan 2019 11:46:32 +0100 Subject: [PATCH] improve performance for codeblocks with highlight.js --- .../tiptap-extensions/src/nodes/CodeBlockHighlight.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js b/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js index 76c690a0..99c1b417 100644 --- a/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js +++ b/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js @@ -122,13 +122,16 @@ export default class CodeBlockHighlight extends Node { init(_, { doc }) { return getDecorations(doc) }, - apply(tr, set) { + apply(transaction, decorationSet) { // TODO: find way to cache decorations // see: https://discuss.prosemirror.net/t/how-to-update-multiple-inline-decorations-on-node-change/1493 - if (tr.docChanged) { - return getDecorations(tr.doc) + + const currentNodeName = transaction.curSelection.$head.parent.type.name + if (transaction.docChanged && currentNodeName === 'code_block') { + return getDecorations(transaction.doc) } - return set.map(tr.mapping, tr.doc) + + return decorationSet.map(transaction.mapping, transaction.doc) }, }, props: {