I have searched for a way to change the default behavior for Enter to be the same as Shift + Enter. To get instead of new
Is it possible to change to this behavior somehow?
I have searched for a way to change the default behavior for Enter to be the same as Shift + Enter. To get instead of new
Is it possible to change to this behavior somehow?
this.editor = new Editor({
content: this.modelValue,
extensions: [
StarterKit,
HardBreak.extend({
addKeyboardShortcuts () {
return {
Enter: () => this.editor.commands.setHardBreak()
}
}
})
]
});
If you're just tryng to achive the line break on your output the same as your editor, you might not need this at all.
I was encountering the same problem and asked myself this question. But by setting my "Enter" key to set a HardBreak, it causes issues with multiple extensions such as headings and list.
It turns out that after a brief inspection of the element inside the editor and my output, it renders a<p>
tag and inside it contain's a <br />
which acts as a line break. BUT, that <br />
tag does not get included on the output so the <p>
tag does not have any height at all.
Two other methods that works:
.ProseMirror p:empty::before {
content: '';
display: inline-block;
}
I attached the ProseMirror css class to my output as well, change it acording to your need. This inserts an empty element so that the <p>
height will be kept.
const CustomStarterKit = StarterKit.configure({
// ...
paragraph: {
HTMLAttributes: {
class: 'min-h-[1rem]'
}
}
});
Or this.
const CustomParagraph = Paragraph.configure({
HTMLAttributes: {
class: 'min-h-[1rem]'
}
});
Then include it in your list of extensions. I was using Tailwind there, but you get the idea.