From 5d2ff8e07c1d997a1d3fdb65fc29cb8d09fedf04 Mon Sep 17 00:00:00 2001 From: Alexandre Moreau Date: Tue, 25 Oct 2022 00:42:31 +0200 Subject: [PATCH] fix: remove attribute if it already exists on the node --- .../format_rich_text_style.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart index 0229d2270f..93ef3ebea9 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart @@ -108,7 +108,16 @@ bool formatTextNodes(EditorState editorState, Attributes attributes) { newAttributes[globalStyleKey] = null; } } - newAttributes.addAll(attributes); + + // if an attribute already exists in the node, it should be removed instead + for (final entry in attributes.entries) { + if (textNode.attributes.containsKey(entry.key) && + textNode.attributes[entry.key] == entry.value) { + // attribute is not added to the node new attributes + } else { + newAttributes.addEntries([entry]); + } + } transaction ..updateNode( textNode,