Explorar o código

fix: remove attribute if it already exists on the node

Alexandre Moreau %!s(int64=2) %!d(string=hai) anos
pai
achega
5d2ff8e07c

+ 10 - 1
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,