improve performance for codeblocks with highlight.js

This commit is contained in:
Philipp Kühn
2019-01-31 11:46:32 +01:00
parent 8d44a4c6fc
commit fce6d9dac9

View File

@@ -122,13 +122,16 @@ export default class CodeBlockHighlight extends Node {
init(_, { doc }) { init(_, { doc }) {
return getDecorations(doc) return getDecorations(doc)
}, },
apply(tr, set) { apply(transaction, decorationSet) {
// TODO: find way to cache decorations // TODO: find way to cache decorations
// see: https://discuss.prosemirror.net/t/how-to-update-multiple-inline-decorations-on-node-change/1493 // 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: { props: {