Some of our editors are currently implementing “br” instead of “p” when using the enter key. To replicate this behaviour I’ve come up with some code based on the baseKeymap and hard break nodes. I’m still learning Prosemirror so I wanted to check to see if it’s seems reasonable to do it this way ?
export function buildBaseKeymap(schema, options) {
let keys = baseKeymap, type;
if ( options && options.enterkey_hardbreak === true ) {
if (type = schema.nodes.hard_break) {
let br = type;
let brcmd = chainCommands(newlineInCode, createParagraphNear, (state, dispatch) => {
let {$from, $to} = state.selection
if ( !$from.parent.isBlock ) return false
if ( $from.parent.type != schema.nodes.paragraph ) return false
if ( dispatch ) {
dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView())
}
return true
}, liftEmptyBlock, splitBlock)
keys["Enter"] = brcmd;
}
}
return keys;
}