diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js index be76ca3d97a14dbc6bb739162dc71efe9d6a29ae..a35f5b99d50e50dcd28ab6951a50bd96f4f0976a 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 175b0b771aba846548b2262681e84c069063a0ad..9c55715f5cd51f799e245ef08eb5019cdd3ff425 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} /> ),