bianjiang 1 жил өмнө
parent
commit
ce627d68d0

+ 11 - 15
src/modules/editor/components/CompUI/basicUI/Text/ckeditor-letter-spacing/LetterSpacingCommand.ts

@@ -8,7 +8,7 @@ export default class LetterSpacingCommand extends Command {
   refresh() {
     const model = this.editor.model;
     const doc = model.document;
-    this.value = doc.selection.getAttribute(Letter_Spacing);
+    this.value = doc.selection.getAttribute(Letter_Spacing) || "0";
     this.isEnabled = model.schema.checkAttributeInSelection(
       doc.selection,
       Letter_Spacing
@@ -21,24 +21,20 @@ export default class LetterSpacingCommand extends Command {
     const selection = document.selection;
     const value = options.value;
     const batch = options.batch;
+
     const updateAttribute = (writer: any) => {
       if (selection.isCollapsed) {
+        return;
+      }
+      const ranges = model.schema.getValidRanges(
+        selection.getRanges(),
+        Letter_Spacing
+      );
+      for (const range of ranges) {
         if (value) {
-          writer.setSelectionAttribute(Letter_Spacing, value);
+          writer.setAttribute(Letter_Spacing, value, range);
         } else {
-          writer.removeSelectionAttribute(Letter_Spacing);
-        }
-      } else {
-        const ranges = model.schema.getValidRanges(
-          selection.getRanges(),
-          Letter_Spacing
-        );
-        for (const range of ranges) {
-          if (value) {
-            writer.setAttribute(Letter_Spacing, value, range);
-          } else {
-            writer.removeAttribute(Letter_Spacing, range);
-          }
+          writer.removeAttribute(Letter_Spacing, range);
         }
       }
     };