import { TextSelection } from 'prosemirror-state';
import { get$Cursor } from "../../../../utils/selection.js";
import { pType } from "../../../base/specs.js";
import { YfmHeadingAttr } from "../const.js";
import { isFoldedHeading } from "../utils.js";
export const openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = (state, dispatch) => {
    const $cursor = get$CursorAtBlockEnd(state.selection);
    if (!$cursor || !isFoldedHeading($cursor.parent))
        return false;
    if (dispatch) {
        const tr = state.tr
            .setNodeAttribute($cursor.before(), YfmHeadingAttr.Folding, false)
            .insert($cursor.after(), pType(state.schema).createAndFill());
        dispatch(tr.setSelection(TextSelection.create(tr.doc, $cursor.after() + 1)).scrollIntoView());
    }
    return true;
};
function get$CursorAtBlockEnd(selection) {
    const $cursor = get$Cursor(selection);
    if (!$cursor || $cursor.parent.isInline || $cursor.parentOffset < $cursor.parent.content.size)
        return null;
    return $cursor;
}
//# sourceMappingURL=openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading.js.map
