chore: Upgrade all of prosemirror (#5366)
Co-authored-by: Apoorv Mishra <apoorvmishra101092@gmail.com>
This commit is contained in:
31
shared/editor/commands/deleteEmptyFirstParagraph.ts
Normal file
31
shared/editor/commands/deleteEmptyFirstParagraph.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Command } from "prosemirror-state";
|
||||
import isNodeActive from "../queries/isNodeActive";
|
||||
|
||||
/**
|
||||
* Deletes the first paragraph node if it is empty and the cursor is at the
|
||||
* beginning of the document.
|
||||
*/
|
||||
const deleteEmptyFirstParagraph: Command = (state, dispatch) => {
|
||||
if (!isNodeActive(state.schema.nodes.paragraph)(state)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state.selection.from !== 1 || state.selection.to !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parent = state.selection.$from.parent;
|
||||
if (parent.textContent !== "" || parent.childCount > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// delete the empty paragraph node
|
||||
dispatch?.(
|
||||
state.tr
|
||||
.delete(state.selection.from - 1, state.selection.from)
|
||||
.scrollIntoView()
|
||||
);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default deleteEmptyFirstParagraph;
|
||||
Reference in New Issue
Block a user