소스 검색

fix: remove attribute if it already exists on the node

Alexandre Moreau 2 년 전
부모
커밋
5d2ff8e07c
1개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. 10 1
      frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart

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