perf: Improve performance of Placeholder extension

This commit is contained in:
Tom Moor
2023-10-16 19:28:41 -04:00
parent 0b7253bb0c
commit a357cbaf8d

View File

@@ -22,14 +22,12 @@ export default class Placeholder extends Extension {
const { doc } = state;
const decorations: Decoration[] = [];
const completelyEmpty =
doc.textContent === "" &&
doc.childCount <= 1 &&
doc.content.size <= 2;
doc.content.size <= 2 &&
doc.textContent === "";
if (completelyEmpty) {
doc.descendants((node, pos) => {
if (!completelyEmpty) {
return;
}
if (pos !== 0 || node.type.name !== "paragraph") {
return;
}
@@ -40,6 +38,7 @@ export default class Placeholder extends Extension {
});
decorations.push(decoration);
});
}
return DecorationSet.create(doc, decorations);
},