Hey there,
I am new to ProseMirror and I am using it wrapped in preact. I didn’t have many problems so far, but now I tried adding hard breaks to my editor. I basically copied the code from the prosemirror-examplesetup and the prosemirror-basic-schema:
const schema = new Schema({
nodes: {
doc: { content: 'block+' },
paragraph: {
content: 'inline*',
group: 'block',
parseDOM: [{ tag: 'p' }],
toDOM() {
return ['p', 0];
},
},
text: {
group: 'inline',
},
hard_break: {
inline: true,
group: 'inline',
selectable: false,
parseDOM: [{ tag: 'br' }],
toDOM() {
return ['br', 0];
},
},
},
marks: {...}
};
const hardBreakCommand = chainCommands(exitCode, (state, dispatch) => {
dispatch(state.tr.replaceSelectionWith(schema.nodes.hard_break.create()).scrollIntoView());
return true;
});
const plugins = [
keymap({
'Mod-b': toggleMark(schema.marks.strong),
'Mod-i': toggleMark(schema.marks.em),
Backspace: undoInputRule,
'Mod-Enter': hardBreakCommand,
'Shift-Enter': hardBreakCommand,
Enter: splitListItem(schema.nodes.list_item),
Tab: sinkListItem(schema.nodes.list_item),
}),
keymap(baseKeymap),
];
Now, if I hit Shift-Enter, a <br>
is inserted, however, I can’t type after it. I am guessing it has something to do with the hard break being an inline block that does not allow content, but shouldn’t I just be able to type after any inline block?
The document looks like this after I inserted the hard break:
{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "hard_break"
}
]
}
]
}