at谁列表

This commit is contained in:
谢思 2021-10-14 15:04:17 +08:00
parent 7fe88aa4d9
commit 4a6012bfa9
1 changed files with 39 additions and 26 deletions

View File

@ -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
})}
</div>
)
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 () => {