Keep previous paragraph node's attributes when user clicks Enter


I’m working on having the text-align and indentation of paragraphs stay the same after a user clicks Enter at the end of a paragraph. I know there’s a chain of commands that get run when a user clicks Enter, with the last one ending with splitBlock.

I want to write a similar method as splitBlockKeepMarks where I can keep the previous paragraph’s node’s attributes in the next paragraph node but am having trouble. My first thought was to create a new paragraph node w/ the previous node’s attrs and insert it at the current from position but that would make two paragraphs once splitBlock is called with the marks getting removed. I can’t use setNodeMarkup because the node doesn’t exist until splitBlock is called.

Does anyone have an idea on how I can do this or has done this before? Still learning more about ProseMirror.

you can just use storeMarks.

first, store the paragraph’ mark and then split the paragraph, and at last use setStoredMarks with you stored marks before within one transaction, like:

   const storedMark = $from.nodeBefore.marks; // you may need to filter some marks like link, etc
   tr.split(pos, 1, pType);

@Xheldon thanks for your response! Yeah, you can keep the marks with storedMarks, similarly to how splitBlockKeepMarks is written in prosemirror-commands but I’m wondering specifically about a node’s attributes.

A paragraph node will have a set of attributes and a set of marks.