Browse Source

Merge branch 'minor' into major

Michael Bromley 3 years ago
parent
commit
776b124ec4

+ 9 - 5
packages/admin-ui/src/lib/core/src/shared/components/rich-text-editor/prosemirror/prosemirror.service.ts

@@ -11,6 +11,7 @@ import { EditorState, Plugin } from 'prosemirror-state';
 import { columnResizing, fixTables, tableEditing } from 'prosemirror-tables';
 import { EditorView } from 'prosemirror-view';
 import { Observable } from 'rxjs';
+
 import { ModalService } from '../../../../providers/modal/modal.service';
 
 import { ContextMenuService } from './context-menu/context-menu.service';
@@ -78,11 +79,14 @@ export class ProsemirrorService {
 
     update(text: string) {
         if (this.editorView) {
-            let state = this.getStateFromText(text);
-            if (document.body.contains(this.editorView.dom)) {
-                const fix = fixTables(state);
-                if (fix) state = state.apply(fix.setMeta('addToHistory', false));
-                this.editorView.updateState(state);
+            const currentText = this.getTextFromState(this.editorView.state);
+            if (text !== currentText) {
+                let state = this.getStateFromText(text);
+                if (document.body.contains(this.editorView.dom)) {
+                    const fix = fixTables(state);
+                    if (fix) state = state.apply(fix.setMeta('addToHistory', false));
+                    this.editorView.updateState(state);
+                }
             }
         }
     }

+ 5 - 3
packages/admin-ui/src/lib/core/src/shared/components/rich-text-editor/rich-text-editor.component.ts

@@ -101,9 +101,11 @@ export class RichTextEditorComponent implements ControlValueAccessor, AfterViewI
     }
 
     writeValue(value: any) {
-        this.value = value;
-        if (this.prosemirrorService) {
-            this.prosemirrorService.update(value);
+        if (value !== this.value) {
+            this.value = value;
+            if (this.prosemirrorService) {
+                this.prosemirrorService.update(value);
+            }
         }
     }
 }