diff --git a/src/modules/tpm/challengesnew/tpm-md-editor.js b/src/modules/tpm/challengesnew/tpm-md-editor.js index f46b478f6..c1feec481 100644 --- a/src/modules/tpm/challengesnew/tpm-md-editor.js +++ b/src/modules/tpm/challengesnew/tpm-md-editor.js @@ -79,7 +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 [atWho, setAtWho] = useState(undefined); const containerId = `mdEditor_${mdID}`; const editorBodyId = `mdEditors_${mdID}`; const tipId = `e_tips_mdEditor_${mdID}`; @@ -107,15 +107,18 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla return ro; } - useEffect(()=>{ - document.addEventListener('click',()=>{setAtWhoVisible(false)}); - }) - function selectAtWho(username){ setAtWhoVisible(false); - setAtWho(username); + const a = editorInstance.cm; + const b = editorInstance.cm.on; + console.log('cm.getValue()', editorInstance.cm) + console.log('onchange', editorInstance.cm.doc.getCursor()); + editorInstance.setValue(initValue.toString()+username); + // editorInstance.cm.on('change',(cm)=>{ + // onchange(cm.getValue()+username); + // }) + // setAtWho(username); // console.log('editorInstance1',editorInstance); - // editorInstance.setValue(initValue.toString()+username); // console.log('editorInstance2',editorInstance); } @@ -131,6 +134,10 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla })} ) + + useEffect(()=>{ + document.addEventListener('click',()=>{setAtWhoVisible(false)}); + }) useEffect(() => { if (editorInstance) { @@ -229,26 +236,32 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla if (!noStorage) { tid = md_elocalStorage(editorInstance, `MDEditor__${containerId}`, containerId) } + editorInstance.cm.on('change', (cm) => { + if(forMember){ + document.onkeydown = (e) => { + console.log('onkeydown', e) + if (e.key === "@") { + // 输入@键后在对应的位置显示可选的项目成员 + // const endOffset = window.getSelection(); + setAtWhoVisible(true); + // const addValue = atWho? cm.getValue()+atWho:cm.getValue(); + // onChange(addValue); + }else{ + setAtWhoVisible(false); + } + }; + } + console.log('change---') + onChange && onChange(cm.getValue()); + // atWho && onChange(addValue+atWho) && setAtWho(undefined); + // if(atWho){ + // onChange(cm.getValue()+atWho); + // setAtWho(undefined); + // }else{ + // onChange(cm.getValue()); + // } + }) if (onChange) { - editorInstance.cm.on('change', (cm) => { - if(forMember){ - document.onkeydown = (e) => { - if (e.key === "@") { - // 输入@键后在对应的位置显示可选的项目成员 - const endOffset = window.getSelection(); - setAtWhoVisible(true); - const addValue = atWho? cm.getValue()+atWho:cm.getValue(); - onChange(addValue); - }else{ - setAtWhoVisible(false); - } - }; - }else{ - onChange(cm.getValue()); - } - // const addValue = atWho? cm.getValue():cm.getValue()+atWho; - - }) } ro = onLayout() return () => {