From 9864d33cfb89844a4a054e90383a194471157e4c Mon Sep 17 00:00:00 2001 From: winetree94 Date: Wed, 8 May 2024 16:00:48 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20fix=20alignment=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/commands/clear-marks.ts | 11 ++++++----- .../core/src/commands/transform-range-to-block.ts | 5 ++++- .../core/src/utils/get-block-container-children.ts | 5 +---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/core/src/commands/clear-marks.ts b/packages/core/src/commands/clear-marks.ts index 92a8f8b6..949ae0e4 100644 --- a/packages/core/src/commands/clear-marks.ts +++ b/packages/core/src/commands/clear-marks.ts @@ -6,11 +6,12 @@ import { Command } from 'prosemirror-state'; */ export const clearMarks = (): Command => (state, dispatch) => { const { from, to } = state.selection; - const tr = state.tr; - tr.removeMark(from, to); - tr.setStoredMarks([]); - if (dispatch) { - dispatch(tr); + let tr = state.tr; + tr = tr.removeMark(from, to); + tr = tr.setStoredMarks([]); + if (!tr.docChanged) { + return false; } + dispatch?.(tr); return true; }; diff --git a/packages/core/src/commands/transform-range-to-block.ts b/packages/core/src/commands/transform-range-to-block.ts index 2cf4d964..0e092568 100644 --- a/packages/core/src/commands/transform-range-to-block.ts +++ b/packages/core/src/commands/transform-range-to-block.ts @@ -28,7 +28,10 @@ export const transformRangeToBlock = if (!nodeType.validContent(node.content)) { return tr; } - tr.setBlockType(pos, pos + node.nodeSize, nodeType, attrs); + tr.setBlockType(pos, pos + node.nodeSize, nodeType, { + ...node.attrs, + ...attrs, + }); return tr; }, tr); selection = state.selection.map(tr.doc, tr.mapping); diff --git a/packages/core/src/utils/get-block-container-children.ts b/packages/core/src/utils/get-block-container-children.ts index ca7f92be..4838cb61 100644 --- a/packages/core/src/utils/get-block-container-children.ts +++ b/packages/core/src/utils/get-block-container-children.ts @@ -8,10 +8,7 @@ export const getBlockContainerChildren = ( ) => { const nodes: NodePair[] = []; doc.nodesBetween(from, to, (node, pos, parent) => { - if ( - parent?.type.spec.group?.includes('block-container') && - node.type.name !== 'table' - ) { + if (parent?.type.spec.group?.includes('block-container')) { nodes.push({ node, pos, parent }); return false; }