From 2ecd6be9db717b0d91845659eaafaf732a59f6b8 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 23 Nov 2022 11:00:40 +0200
Subject: [PATCH] diable tool on feedback

---
 .../components/FeedbackComponent.js            | 17 +++++++++++++++++
 .../components/FeedbackComponent.js            | 18 ++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/wax-prosemirror-services/src/MatchingService/components/FeedbackComponent.js b/wax-prosemirror-services/src/MatchingService/components/FeedbackComponent.js
index d10c9dfb7..e063a5825 100644
--- a/wax-prosemirror-services/src/MatchingService/components/FeedbackComponent.js
+++ b/wax-prosemirror-services/src/MatchingService/components/FeedbackComponent.js
@@ -1,5 +1,6 @@
 import React, { useContext, useRef, useState } from 'react';
 import styled from 'styled-components';
+import { TextSelection } from 'prosemirror-state';
 import { WaxContext, DocumentHelpers } from 'wax-prosemirror-core';
 
 const FeedBack = styled.div`
@@ -31,6 +32,7 @@ export default ({ node, getPos, readOnly }) => {
   const context = useContext(WaxContext);
   const {
     pmViews: { main },
+    activeView,
   } = context;
   const [feedBack, setFeedBack] = useState(node.attrs.feedback);
   const feedBackRef = useRef(null);
@@ -48,9 +50,23 @@ export default ({ node, getPos, readOnly }) => {
         );
       }
     });
+    setNullSelection();
     return false;
   };
 
+  const setNullSelection = () => {
+    activeView.dispatch(
+      activeView.state.tr.setSelection(
+        TextSelection.create(activeView.state.tr.doc, null),
+      ),
+    );
+  };
+
+  const onFocus = () => {
+    setTimeout(() => {
+      setNullSelection();
+    }, 50);
+  };
   return (
     <FeedBack>
       <FeedBackLabel>Feedback</FeedBackLabel>
@@ -58,6 +74,7 @@ export default ({ node, getPos, readOnly }) => {
         autoFocus="autoFocus"
         disabled={readOnly}
         onChange={feedBackInput}
+        onFocus={onFocus}
         placeholder="Insert feedback"
         ref={feedBackRef}
         type="text"
diff --git a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/FeedbackComponent.js b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/FeedbackComponent.js
index 5508301af..e736db531 100644
--- a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/FeedbackComponent.js
+++ b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/FeedbackComponent.js
@@ -1,5 +1,6 @@
 import React, { useContext, useRef, useState } from 'react';
 import styled from 'styled-components';
+import { TextSelection } from 'prosemirror-state';
 import { WaxContext, DocumentHelpers } from 'wax-prosemirror-core';
 
 const FeedBack = styled.div`
@@ -30,6 +31,7 @@ export default ({ node, getPos, readOnly }) => {
   const context = useContext(WaxContext);
   const {
     pmViews: { main },
+    activeView,
   } = context;
 
   const [feedBack, setFeedBack] = useState(node.attrs.feedback);
@@ -48,15 +50,31 @@ export default ({ node, getPos, readOnly }) => {
         );
       }
     });
+    setNullSelection();
     return false;
   };
 
+  const setNullSelection = () => {
+    activeView.dispatch(
+      activeView.state.tr.setSelection(
+        TextSelection.create(activeView.state.tr.doc, null),
+      ),
+    );
+  };
+
+  const onFocus = () => {
+    setTimeout(() => {
+      setNullSelection();
+    }, 50);
+  };
+
   return (
     <FeedBack>
       <FeedBackLabel>Feedback</FeedBackLabel>
       <FeedBackInput
         autoFocus="autoFocus"
         onChange={feedBackInput}
+        onFocus={onFocus}
         placeholder="Insert feedback"
         readOnly={readOnly}
         ref={feedBackRef}
-- 
GitLab