diff --git a/src/modules/tpm/challengesnew/tpm-md-editor.js b/src/modules/tpm/challengesnew/tpm-md-editor.js index 9d174a657..f46b478f6 100644 --- a/src/modules/tpm/challengesnew/tpm-md-editor.js +++ b/src/modules/tpm/challengesnew/tpm-md-editor.js @@ -79,6 +79,7 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla const resizeBarEl = useRef(); const [editorInstance, setEditorInstance] = useState(); const [atWhoVisible, setAtWhoVisible] = useState(false); + const [atWho, setAtWho] = useState(undefined); const containerId = `mdEditor_${mdID}`; const editorBodyId = `mdEditors_${mdID}`; const tipId = `e_tips_mdEditor_${mdID}`; @@ -112,7 +113,10 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla function selectAtWho(username){ setAtWhoVisible(false); - editorInstance.setValue(initValue.toString()+username); + setAtWho(username); + // console.log('editorInstance1',editorInstance); + // editorInstance.setValue(initValue.toString()+username); + // console.log('editorInstance2',editorInstance); } const atWhoList = ( @@ -231,14 +235,19 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla document.onkeydown = (e) => { if (e.key === "@") { // 输入@键后在对应的位置显示可选的项目成员 - const selection = window.getSelection().anchorOffset; + const endOffset = window.getSelection(); setAtWhoVisible(true); + const addValue = atWho? cm.getValue()+atWho:cm.getValue(); + onChange(addValue); }else{ setAtWhoVisible(false); } }; + }else{ + onChange(cm.getValue()); } - onChange(cm.getValue()) + // const addValue = atWho? cm.getValue():cm.getValue()+atWho; + }) } ro = onLayout()