I have a paragraph
node and math_inline
node. I would like to select of piece of text inside my paragraph
and wrap it inside math_inline
node. I tried to use wrapIn
command but without any success. I would like to use the same command to simply insert math_inline
command in the current cursor position. What is the best way to achieve that?
name: "math_inline",
group: "inline math",
content: "text*", // important!
inline: true, // important!
atom: true, // important!
code: true,
EDIT: I did that with the following piece of code:
setMathInline:
() =>
({ chain, state, tr }) => {
let { $from, $to } = state.selection;
let index = $from.index();
if (!$from.parent.canReplaceWith(index, index, this.type)) {
return false;
}
let content = state.doc.cut(
state.selection.from,
state.selection.to
).textContent;
console.log(content);
return chain()
.focus()
.command(({ tr }) => {
tr.replaceSelectionWith(
this.type.create(
{},
content ? state.schema.text(content) : undefined
)
);
tr.setSelection(NodeSelection.create(tr.doc, $from.pos));
return true;
})
.run();
Is that OK? Another problem is that this way the cursor is positioned at the beginning od the math block while I would like to move it to the very end. How can I do that?