"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = void 0;
const prosemirror_state_1 = require("prosemirror-state");
const selection_1 = require("../../../../utils/selection.js");
const specs_1 = require("../../../base/specs.js");
const const_1 = require("../const.js");
const utils_1 = require("../utils.js");
const openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = (state, dispatch) => {
    const $cursor = get$CursorAtBlockEnd(state.selection);
    if (!$cursor || !(0, utils_1.isFoldedHeading)($cursor.parent))
        return false;
    if (dispatch) {
        const tr = state.tr
            .setNodeAttribute($cursor.before(), const_1.YfmHeadingAttr.Folding, false)
            .insert($cursor.after(), (0, specs_1.pType)(state.schema).createAndFill());
        dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, $cursor.after() + 1)).scrollIntoView());
    }
    return true;
};
exports.openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading;
function get$CursorAtBlockEnd(selection) {
    const $cursor = (0, selection_1.get$Cursor)(selection);
    if (!$cursor || $cursor.parent.isInline || $cursor.parentOffset < $cursor.parent.content.size)
        return null;
    return $cursor;
}
//# sourceMappingURL=openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading.js.map
