@@ -3,6 +3,7 @@ import { helpers } from '@core/index.js';
33import { Plugin , PluginKey } from 'prosemirror-state' ;
44import { ReplaceStep } from 'prosemirror-transform' ;
55import { v4 as uuidv4 } from 'uuid' ;
6+ import { Transaction } from 'prosemirror-state' ;
67
78const { findChildren } = helpers ;
89const SD_BLOCK_ID_ATTRIBUTE_NAME = 'sdBlockId' ;
@@ -122,13 +123,12 @@ export const BlockNode = Extension.create({
122123 // Check for new block nodes and if none found, we don't need to do anything
123124 if ( hasInitialized && ! checkForNewBlockNodesInTrs ( transactions ) ) return null ;
124125
125- let tr = null ;
126+ const { tr } = newState ;
126127 let changed = false ;
127128 newState . doc . descendants ( ( node , pos ) => {
128129 // Only allow block nodes with a valid sdBlockId attribute
129130 if ( ! nodeAllowsSdBlockIdAttr ( node ) || ! nodeNeedsSdBlockId ( node ) ) return null ;
130131
131- tr = tr ?? newState . tr ;
132132 tr . setNodeMarkup (
133133 pos ,
134134 undefined ,
@@ -141,7 +141,14 @@ export const BlockNode = Extension.create({
141141 changed = true ;
142142 } ) ;
143143
144- if ( changed && ! hasInitialized ) hasInitialized = true ;
144+ if ( changed && ! hasInitialized ) {
145+ hasInitialized = true ;
146+ }
147+
148+ // Restore marks if they exist.
149+ // `tr.setNodeMarkup` resets the stored marks.
150+ tr . setStoredMarks ( newState . tr . storedMarks ) ;
151+
145152 return changed ? tr : null ;
146153 } ,
147154 } ) ,
@@ -171,7 +178,8 @@ export const nodeNeedsSdBlockId = (node) => {
171178/**
172179 * Check for new block nodes in ProseMirror transactions.
173180 * Iterate through the list of transactions, and in each tr check if there are any new block nodes.
174- * @param {Array<Transaction> } transactions - The ProseMirror transactions to check.
181+ * @readonly
182+ * @param {readonly Transaction[] } transactions - The ProseMirror transactions to check.
175183 * @returns {boolean } - True if new block nodes are found, false otherwise.
176184 */
177185export const checkForNewBlockNodesInTrs = ( transactions ) => {
0 commit comments