From b57d0db51c175c2bc6e2a15000d0019ba57f1127 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 14 Jul 2021 22:33:36 +0300
Subject: [PATCH] simulate enter in progress

---
 .../MultipleChoiceQuestion.js                      | 14 ++++++++++++--
 .../components/ToolBarBtn.js                       | 12 +++++-------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js
index be76ca3d9..a35f5b99d 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js
@@ -6,6 +6,14 @@ import { Fragment } from 'prosemirror-model';
 import { v4 as uuidv4 } from 'uuid';
 import ToolBarBtn from './components/ToolBarBtn';
 
+const simulateKey = (view, keyCode, key) => {
+  let event = document.createEvent('Event');
+  event.initEvent('keydown', true, true);
+  event.keyCode = keyCode;
+  event.key = event.code = key;
+  return view.someProp('handleKeyDown', f => f(view, event));
+};
+
 const createQuestion = (state, dispatch, tr) => {
   const { empty, $from, $to } = state.selection;
   let content = Fragment.empty;
@@ -26,8 +34,10 @@ class MultipleChoiceQuestion extends Tools {
   name = 'Multiple Choice';
 
   get run() {
-    return (state, dispatch) => {
-      console.log(state);
+    return view => {
+      simulateKey(view, 13, 'Enter');
+
+      const { state, dispatch } = view;
       const { from, to } = state.selection;
       const { tr } = state;
 
diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/ToolBarBtn.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/ToolBarBtn.js
index 175b0b771..9c55715f5 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/ToolBarBtn.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/ToolBarBtn.js
@@ -27,12 +27,7 @@ const ToolBarBtn = ({ view = {}, item }) => {
     return editable;
   });
 
-  const { dispatch, state } = view;
-
-  const handleMouseDown = (e, editorState, editorDispatch) => {
-    e.preventDefault();
-    run(editorState, dispatch);
-  };
+  const { state } = view;
 
   const isActive = !!(
     active(state, activeViewId) && select(state, activeViewId)
@@ -48,7 +43,10 @@ const ToolBarBtn = ({ view = {}, item }) => {
         disabled={isDisabled}
         iconName={icon}
         label={label}
-        onMouseDown={e => handleMouseDown(e, view.state, view.dispatch)}
+        onMouseDown={e => {
+          e.preventDefault();
+          run(main);
+        }}
         title={title}
       />
     ),
-- 
GitLab