I am using baseKeyMap from prose mirro command. Using this I can use enter commands. But shift-enter command is not caught and I don’t see line break happening. What to do?
Well, yes, the base keymap doesn’t bind anything to Shift-Enter. You’ll have to bind your own command to it, possibly using the bindings from prosemirror-example-setup as inspiration.
Thanks for replying! Could you please point me to those examples and resources on how to do it? I m still new to this world of prose commands!
Thanks.
Can we bind shift enter command to enter key binding somehow?
So this is my schema: const pillContainerSchema = new Schema({ nodes: { doc: { content: ‘line*’ }, line: { content: ‘(pill|text|hard_break)', parseDOM: [{ tag: ‘p’ }], toDOM() { return [‘p’, 0]; } }, text: {}, hard_break: { inline: true, selectable: false, parseDOM: [{ tag: ‘br’ }], toDOM() { return [‘br’,0]; } }, pill: { content: 'text’, inline: true, isolating: true, attrs: { pillValue: {}, pillUniqueId: {}, pillHasTransforms: { default: false }, showPillIcon: { default: false }, pillIcon: {}, iconTooltipText: {} }, toDOM(node) { return [‘pill’, node.attrs, 0]; }, parseDOM: [{ tag: ‘pill’ }] } } }); // Key binding for Shift-Enter to insert a hard break const hardBreakKeymap = keymap({ ‘Shift-Enter’: (state, dispatch) => { const { hard_break } = state.schema.nodes;
// Create the transaction with the hard break node
const tr = state.tr.replaceSelectionWith(hard_break.create()).scrollIntoView();
// If the document was changed, persist the change
if (dispatch) {
dispatch(tr);
}
return true;
}
});
// Enable multiline and apply base keymap
if (multiLine) {
// Push the hardBreakKeymap and baseKeymap into the plugins
stateConfig.plugins.push(hardBreakKeymap, keymap(baseKeymap));
}
Schema: const pillContainerSchema = new Schema({ nodes: { doc: { content: 'line*' }, line: { content: '(pill|text|hard_break)*', parseDOM: [{ tag: 'p' }], toDOM() { return ['p', 0]; } }, text: {}, hard_break: { inline: true, selectable: false, parseDOM: [{ tag: 'br' }], toDOM() { return ['br',0]; } }, pill: { content: 'text*', inline: true, isolating: true, attrs: { pillValue: {}, pillUniqueId: {}, pillHasTransforms: { default: false }, showPillIcon: { default: false }, pillIcon: {}, iconTooltipText: {} }, toDOM(node) { return ['pill', node.attrs, 0]; }, parseDOM: [{ tag: 'pill' }] } } });
When i do shift-return i get a new line but i m not able type anything. Also for some reason when I used hard_break: { inline: true, selectable: false, parseDOM: [{ tag: ‘br’ }], toDOM() { return [‘br’]; } }, I was able to get new line. But a space comes in starting. I am able to type in new line but for some reason it is not getting persisted in editor
Can you help?