From 4a78318a74b300e8abb9ff2e0df2f428409b7a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 18 Nov 2020 14:46:47 +0100 Subject: [PATCH] add type option to updateNodeAttributes --- packages/core/src/commands/updateNodeAttributes.ts | 7 +++++-- packages/extension-text-align/src/index.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/src/commands/updateNodeAttributes.ts b/packages/core/src/commands/updateNodeAttributes.ts index 1ac80d3b..4fd60868 100644 --- a/packages/core/src/commands/updateNodeAttributes.ts +++ b/packages/core/src/commands/updateNodeAttributes.ts @@ -1,11 +1,14 @@ +import { NodeType } from 'prosemirror-model' +import getNodeType from '../utils/getNodeType' import { Command } from '../types' -export default (attributes: {}): Command => ({ tr, state, dispatch }) => { +export default (typeOrName: string | NodeType, attributes: {}): Command => ({ tr, state, dispatch }) => { + const type = getNodeType(typeOrName, state.schema) const { selection } = tr const { from, to } = selection state.doc.nodesBetween(from, to, (node, pos) => { - if (!node.type.isText && dispatch) { + if (node.type === type && dispatch) { tr.setNodeMarkup(pos, undefined, { ...node.attrs, ...attributes, diff --git a/packages/extension-text-align/src/index.ts b/packages/extension-text-align/src/index.ts index cecf0414..7477e145 100644 --- a/packages/extension-text-align/src/index.ts +++ b/packages/extension-text-align/src/index.ts @@ -42,13 +42,13 @@ const TextAlign = Extension.create({ return false } - return commands.updateNodeAttributes({ textAlign: alignment }) + return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: alignment })) }, /** * Unset the text align attribute */ unsetTextAlign: (): Command => ({ commands }) => { - return commands.updateNodeAttributes({ textAlign: null }) + return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: null })) }, } },