chore: Upgrade all of prosemirror (#5366)
Co-authored-by: Apoorv Mishra <apoorvmishra101092@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { NodeType } from "prosemirror-model";
|
||||
import { EditorState } from "prosemirror-state";
|
||||
import { Dispatch } from "../types";
|
||||
import { Command } from "prosemirror-state";
|
||||
|
||||
/**
|
||||
* Converts the current node to a paragraph when pressing backspace at the
|
||||
@@ -9,28 +8,28 @@ import { Dispatch } from "../types";
|
||||
* @param type The node type
|
||||
* @returns A prosemirror command.
|
||||
*/
|
||||
export default function backspaceToParagraph(type: NodeType) {
|
||||
return (state: EditorState, dispatch: Dispatch) => {
|
||||
export default function backspaceToParagraph(type: NodeType): Command {
|
||||
return (state, dispatch) => {
|
||||
const { $from, from, to, empty } = state.selection;
|
||||
|
||||
// if the selection has anything in it then use standard delete behavior
|
||||
if (!empty) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// check we're in a matching node
|
||||
if ($from.parent.type !== type) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if we're at the beginning of the heading
|
||||
const $pos = state.doc.resolve(from - 1);
|
||||
if ($pos.parent === $from.parent) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// okay, replace it with a paragraph
|
||||
dispatch(
|
||||
dispatch?.(
|
||||
state.tr
|
||||
.setBlockType(from, to, type.schema.nodes.paragraph)
|
||||
.scrollIntoView()
|
||||
|
||||
Reference in New Issue
Block a user