From be36817ce64e0bb065ce0a7da8d6bca78ed1f162 Mon Sep 17 00:00:00 2001 From: Artem Nistuley Date: Wed, 3 Sep 2025 13:18:11 +0300 Subject: [PATCH] fix: restore stored marks if they exist --- .../src/extensions/block-node/block-node.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/super-editor/src/extensions/block-node/block-node.js b/packages/super-editor/src/extensions/block-node/block-node.js index a384f0dc4..0d54019b5 100644 --- a/packages/super-editor/src/extensions/block-node/block-node.js +++ b/packages/super-editor/src/extensions/block-node/block-node.js @@ -3,6 +3,7 @@ import { helpers } from '@core/index.js'; import { Plugin, PluginKey } from 'prosemirror-state'; import { ReplaceStep } from 'prosemirror-transform'; import { v4 as uuidv4 } from 'uuid'; +import { Transaction } from 'prosemirror-state'; const { findChildren } = helpers; const SD_BLOCK_ID_ATTRIBUTE_NAME = 'sdBlockId'; @@ -122,13 +123,12 @@ export const BlockNode = Extension.create({ // Check for new block nodes and if none found, we don't need to do anything if (hasInitialized && !checkForNewBlockNodesInTrs(transactions)) return null; - let tr = null; + const { tr } = newState; let changed = false; newState.doc.descendants((node, pos) => { // Only allow block nodes with a valid sdBlockId attribute if (!nodeAllowsSdBlockIdAttr(node) || !nodeNeedsSdBlockId(node)) return null; - tr = tr ?? newState.tr; tr.setNodeMarkup( pos, undefined, @@ -141,7 +141,14 @@ export const BlockNode = Extension.create({ changed = true; }); - if (changed && !hasInitialized) hasInitialized = true; + if (changed && !hasInitialized) { + hasInitialized = true; + } + + // Restore marks if they exist. + // `tr.setNodeMarkup` resets the stored marks. + tr.setStoredMarks(newState.tr.storedMarks); + return changed ? tr : null; }, }), @@ -171,7 +178,8 @@ export const nodeNeedsSdBlockId = (node) => { /** * Check for new block nodes in ProseMirror transactions. * Iterate through the list of transactions, and in each tr check if there are any new block nodes. - * @param {Array} transactions - The ProseMirror transactions to check. + * @readonly + * @param {readonly Transaction[]} transactions - The ProseMirror transactions to check. * @returns {boolean} - True if new block nodes are found, false otherwise. */ export const checkForNewBlockNodesInTrs = (transactions) => {