import { EditorSelection } from '@codemirror/state';
import { wrapToBlock } from "./helpers.js";
export const wrapToCodeBlock = wrapToBlock(({ lineBreak }) => '```' + lineBreak, ({ lineBreak }) => lineBreak + '```');
export const wrapToInlineCode = ({ state, dispatch }) => {
    const tr = state.changeByRange((range) => {
        const content = state.sliceDoc(range.from, range.to);
        const hasBacktick = content.includes('`');
        const markup = hasBacktick ? '``' : '`';
        const before = `${markup}${content.startsWith('`') ? ' ' : ''}`;
        const after = `${content.endsWith('`') ? ' ' : ''}${markup}`;
        const changeSpec = [
            { from: range.from, insert: before },
            { from: range.to, insert: after },
        ];
        const changes = state.changes(changeSpec);
        return {
            changes,
            range: range.empty
                ? EditorSelection.range(range.anchor + 1, range.head + 1, range.goalColumn, range.bidiLevel ?? undefined)
                : range.map(changes),
        };
    });
    dispatch(state.update(tr));
    return true;
};
//# sourceMappingURL=code.js.map
