From 4add2660476c95b56d46475c446b2b14fdf8d5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=80=9D?= <2897217417@qq.com> Date: Fri, 15 Oct 2021 11:36:51 +0800 Subject: [PATCH] =?UTF-8?q?at=E8=B0=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tpm/challengesnew/css/newquestion.css | 2 +- .../tpm/challengesnew/tpm-md-editor.js | 44 +++++++------------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/modules/tpm/challengesnew/css/newquestion.css b/src/modules/tpm/challengesnew/css/newquestion.css index ca1ebb05..46bb22c3 100644 --- a/src/modules/tpm/challengesnew/css/newquestion.css +++ b/src/modules/tpm/challengesnew/css/newquestion.css @@ -15,7 +15,7 @@ background: #FFFFFF; box-shadow: 0px 4px 8px 2px rgba(212, 212, 212, 0.5); border-radius: 4px; - top: 100px; + top: 60px; left: 100px; overflow-y: scroll; cursor: pointer; diff --git a/src/modules/tpm/challengesnew/tpm-md-editor.js b/src/modules/tpm/challengesnew/tpm-md-editor.js index c1feec48..eae4f23e 100644 --- a/src/modules/tpm/challengesnew/tpm-md-editor.js +++ b/src/modules/tpm/challengesnew/tpm-md-editor.js @@ -79,7 +79,6 @@ 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}`; @@ -109,19 +108,17 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla function selectAtWho(username){ setAtWhoVisible(false); - 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); - // console.log('editorInstance2',editorInstance); + const cm = editorInstance.cm; + //获取鼠标所在行的行数和ch + const cursor = cm.doc.getCursor(); + const line = cursor.line;//行 + const ch = cursor.ch;//列 + //替换最后的内容 + cm.replaceRange(username+" ",{line,ch},{line,ch}); } + console.log('window.event',window.event); + const atWhoList = (
{users && users.map((item,key)=>{ @@ -236,31 +233,22 @@ 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){ + //当光标或选中内容时触发绑定@事件 + editorInstance.cm.on("cursorActivity", () => { + 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{ + } else { setAtWhoVisible(false); } }; } - console.log('change---') + }); + editorInstance.cm.on("change", (cm) => { onChange && onChange(cm.getValue()); - // atWho && onChange(addValue+atWho) && setAtWho(undefined); - // if(atWho){ - // onChange(cm.getValue()+atWho); - // setAtWho(undefined); - // }else{ - // onChange(cm.getValue()); - // } - }) + }); if (onChange) { } ro = onLayout()