From ef2b2a0b1fd5ae8ba21bd1f23671fe8adf319a88 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Mon, 6 Nov 2023 20:22:05 +0200
Subject: [PATCH] create empty paragraphs

---
 .../components/EditorComponent.js                      |  8 +++++++-
 .../MultipleChoiceQuestionService/helpers/helpers.js   | 10 ++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/components/EditorComponent.js b/wax-questions-service/src/MultipleChoiceQuestionService/components/EditorComponent.js
index 9a94fd2e1..303f6ff93 100644
--- a/wax-questions-service/src/MultipleChoiceQuestionService/components/EditorComponent.js
+++ b/wax-questions-service/src/MultipleChoiceQuestionService/components/EditorComponent.js
@@ -209,6 +209,8 @@ const QuestionEditorComponent = ({
   }, []);
 
   const dispatchTransaction = tr => {
+    console.log(tr.getMeta('addToHistoryFromOutside'));
+    const addToHistory = !tr.getMeta('exludeToHistoryFromOutside');
     const { state, transactions } = questionView.state.applyTransaction(tr);
     questionView.updateState(state);
     context.updateView({}, questionId);
@@ -222,7 +224,11 @@ const QuestionEditorComponent = ({
           outerTr.step(steps[j].map(offsetMap));
       }
       if (outerTr.docChanged)
-        view.dispatch(outerTr.setMeta('outsideView', questionId));
+        view.dispatch(
+          outerTr
+            .setMeta('outsideView', questionId)
+            .setMeta('addToHistory', addToHistory),
+        );
     }
   };
 
diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/helpers/helpers.js b/wax-questions-service/src/MultipleChoiceQuestionService/helpers/helpers.js
index 221982fc5..60b6c8733 100644
--- a/wax-questions-service/src/MultipleChoiceQuestionService/helpers/helpers.js
+++ b/wax-questions-service/src/MultipleChoiceQuestionService/helpers/helpers.js
@@ -17,7 +17,9 @@ const createEmptyParagraph = (context, newAnswerId) => {
     if (context.pmViews[newAnswerId].dispatch) {
       const type = context.pmViews.main.state.schema.nodes.paragraph;
       context.pmViews[newAnswerId].dispatch(
-        context.pmViews[newAnswerId].state.tr.insert(0, type.create()),
+        context.pmViews[newAnswerId].state.tr
+          .insert(0, type.create())
+          .setMeta('exludeToHistoryFromOutside', true),
       );
     }
     context.pmViews[newAnswerId].dispatch(
@@ -80,9 +82,9 @@ const createOptions = (main, context, parentType, questionType, answerType) => {
   dispatch(tr);
   setTimeout(() => {
     context.pmViews[question.attrs.id].focus();
-    //   createEmptyParagraph(context, firstOption.attrs.id);
-    //   createEmptyParagraph(context, secondOption.attrs.id);
-    //   createEmptyParagraph(context, question.attrs.id);
+    createEmptyParagraph(context, firstOption.attrs.id);
+    createEmptyParagraph(context, secondOption.attrs.id);
+    createEmptyParagraph(context, question.attrs.id);
   }, 50);
 
   return true;
-- 
GitLab