fix: Document empty placeholder changes when focused
This commit is contained in:
@@ -116,13 +116,16 @@ export default class BlockMenuTrigger extends Extension {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const decorations: Decoration[] = [];
|
|
||||||
const isEmpty = parent && parent.node.content.size === 0;
|
|
||||||
const isSlash = parent && parent.node.textContent === "/";
|
|
||||||
const isTopLevel = state.selection.$from.depth === 1;
|
const isTopLevel = state.selection.$from.depth === 1;
|
||||||
|
if (!isTopLevel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isTopLevel) {
|
const decorations: Decoration[] = [];
|
||||||
if (isEmpty) {
|
const isEmptyNode = parent && parent.node.content.size === 0;
|
||||||
|
const isSlash = parent && parent.node.textContent === "/";
|
||||||
|
|
||||||
|
if (isEmptyNode) {
|
||||||
decorations.push(
|
decorations.push(
|
||||||
Decoration.widget(
|
Decoration.widget(
|
||||||
parent.pos,
|
parent.pos,
|
||||||
@@ -138,6 +141,8 @@ export default class BlockMenuTrigger extends Extension {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isEmptyDoc = state.doc.textContent === "";
|
||||||
|
if (!isEmptyDoc) {
|
||||||
decorations.push(
|
decorations.push(
|
||||||
Decoration.node(
|
Decoration.node(
|
||||||
parent.pos,
|
parent.pos,
|
||||||
@@ -149,24 +154,16 @@ export default class BlockMenuTrigger extends Extension {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else if (isSlash) {
|
||||||
if (isSlash) {
|
|
||||||
decorations.push(
|
decorations.push(
|
||||||
Decoration.node(
|
Decoration.node(parent.pos, parent.pos + parent.node.nodeSize, {
|
||||||
parent.pos,
|
|
||||||
parent.pos + parent.node.nodeSize,
|
|
||||||
{
|
|
||||||
class: "placeholder",
|
class: "placeholder",
|
||||||
"data-empty-text": ` ${this.options.dictionary.newLineWithSlash}`,
|
"data-empty-text": ` ${this.options.dictionary.newLineWithSlash}`,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DecorationSet.create(state.doc, decorations);
|
return DecorationSet.create(state.doc, decorations);
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user