From 0ff4ae71ccf57eef2dc34d072658c2e2b4d4993c Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 13 Oct 2021 13:48:42 +0300
Subject: [PATCH] push to history

---
 .../FillTheGapNodeView.js                     | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js b/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js
index 53b465989..f1c34d5c6 100644
--- a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js
+++ b/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js
@@ -23,6 +23,26 @@ export default class MultipleChoiceNodeView extends AbstractNodeView {
   }
 
   update(node) {
+    // if (!node.sameMarkup(this.node)) return false;
+    this.node = node;
+    if (this.context.view[node.attrs.id]) {
+      const { state } = this.context.view[node.attrs.id];
+      const start = node.content.findDiffStart(state.doc.content);
+      if (start != null) {
+        let { a: endA, b: endB } = node.content.findDiffEnd(state.doc.content);
+        const overlap = start - Math.min(endA, endB);
+        if (overlap > 0) {
+          endA += overlap;
+          endB += overlap;
+        }
+        this.context.view[node.attrs.id].dispatch(
+          state.tr
+            .replace(start, endB, node.slice(start, endA))
+            .setMeta('fromOutside', true),
+        );
+      }
+    }
+
     return true;
   }
 
@@ -31,12 +51,6 @@ export default class MultipleChoiceNodeView extends AbstractNodeView {
   }
 
   stopEvent(event) {
-    console.log(
-      this.context.view[this.node.attrs.id] !== undefined &&
-        event.target !== undefined &&
-        this.context.view[this.node.attrs.id].dom.contains(event.target),
-    );
-
     return (
       this.context.view[this.node.attrs.id] !== undefined &&
       event.target !== undefined &&
-- 
GitLab