diff --git a/wax-prosemirror-services/src/MatchingService/components/FeedbackComponent.js b/wax-prosemirror-services/src/MatchingService/components/FeedbackComponent.js index d10c9dfb700edf2ee70de64757b44e71263aa1b8..e063a58257853bbf836e3e09723ef91f1d86ad9d 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 5508301af54ae37de0835868bdf65d219ab2e078..e736db5314f27f5c033cd048426ffe6f3b6ece70 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}