This commit is contained in:
谢思 2021-10-14 09:11:37 +08:00
parent bc6ef583fb
commit 7fe88aa4d9
1 changed files with 12 additions and 3 deletions

View File

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