fix: Document empty placeholder changes when focused
This commit is contained in:
@@ -116,28 +116,33 @@ 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;
|
||||||
decorations.push(
|
const isSlash = parent && parent.node.textContent === "/";
|
||||||
Decoration.widget(
|
|
||||||
parent.pos,
|
|
||||||
() => {
|
|
||||||
button.addEventListener("click", () => {
|
|
||||||
this.editor.events.emit(EventType.blockMenuOpen, "");
|
|
||||||
});
|
|
||||||
return button;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "block-trigger",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
if (isEmptyNode) {
|
||||||
|
decorations.push(
|
||||||
|
Decoration.widget(
|
||||||
|
parent.pos,
|
||||||
|
() => {
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
this.editor.events.emit(EventType.blockMenuOpen, "");
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "block-trigger",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
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(parent.pos, parent.pos + parent.node.nodeSize, {
|
||||||
Decoration.node(
|
class: "placeholder",
|
||||||
parent.pos,
|
"data-empty-text": ` ${this.options.dictionary.newLineWithSlash}`,
|
||||||
parent.pos + parent.node.nodeSize,
|
})
|
||||||
{
|
);
|
||||||
class: "placeholder",
|
|
||||||
"data-empty-text": ` ${this.options.dictionary.newLineWithSlash}`,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DecorationSet.create(state.doc, decorations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return DecorationSet.create(state.doc, decorations);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user