Skip to content

Commit 59341fd

Browse files
authored
fix: preserve marks across a shift+enter #1672 (#1743)
1 parent f466baf commit 59341fd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/core/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export const KeyboardShortcutsExtension = Extension.create<{
434434
]);
435435

436436
const handleEnter = (withShift = false) => {
437-
return this.editor.commands.first(({ commands }) => [
437+
return this.editor.commands.first(({ commands, tr }) => [
438438
// Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
439439
// of the block.
440440
() =>
@@ -486,9 +486,21 @@ export const KeyboardShortcutsExtension = Extension.create<{
486486
// both enter and shift+enter.
487487
blockHardBreakShortcut === "enter"
488488
) {
489-
return commands.insertContent({
490-
type: "hardBreak",
491-
});
489+
const marks =
490+
tr.storedMarks ||
491+
tr.selection.$head
492+
.marks()
493+
.filter((m) =>
494+
this.editor.extensionManager.splittableMarks.includes(
495+
m.type.name,
496+
),
497+
);
498+
499+
tr.insert(
500+
tr.selection.head,
501+
tr.doc.type.schema.nodes.hardBreak.create(),
502+
).ensureMarks(marks);
503+
return true;
492504
}
493505

494506
return false;

0 commit comments

Comments
 (0)