at谁列表

This commit is contained in:
谢思 2021-10-15 11:36:51 +08:00
parent 4a6012bfa9
commit 4add266047
2 changed files with 17 additions and 29 deletions

View File

@ -15,7 +15,7 @@
background: #FFFFFF; background: #FFFFFF;
box-shadow: 0px 4px 8px 2px rgba(212, 212, 212, 0.5); box-shadow: 0px 4px 8px 2px rgba(212, 212, 212, 0.5);
border-radius: 4px; border-radius: 4px;
top: 100px; top: 60px;
left: 100px; left: 100px;
overflow-y: scroll; overflow-y: scroll;
cursor: pointer; cursor: pointer;

View File

@ -79,7 +79,6 @@ 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}`;
@ -109,19 +108,17 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
function selectAtWho(username){ function selectAtWho(username){
setAtWhoVisible(false); setAtWhoVisible(false);
const a = editorInstance.cm; const cm = editorInstance.cm;
const b = editorInstance.cm.on; //获取鼠标所在行的行数和ch
console.log('cm.getValue()', editorInstance.cm) const cursor = cm.doc.getCursor();
console.log('onchange', editorInstance.cm.doc.getCursor()); const line = cursor.line;//行
editorInstance.setValue(initValue.toString()+username); const ch = cursor.ch;//列
// editorInstance.cm.on('change',(cm)=>{ //替换最后的内容
// onchange(cm.getValue()+username); cm.replaceRange(username+" ",{line,ch},{line,ch});
// })
// setAtWho(username);
// console.log('editorInstance1',editorInstance);
// console.log('editorInstance2',editorInstance);
} }
console.log('window.event',window.event);
const atWhoList = ( const atWhoList = (
<div className="at_who_list"> <div className="at_who_list">
{users && users.map((item,key)=>{ {users && users.map((item,key)=>{
@ -236,31 +233,22 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
if (!noStorage) { if (!noStorage) {
tid = md_elocalStorage(editorInstance, `MDEditor__${containerId}`, containerId) tid = md_elocalStorage(editorInstance, `MDEditor__${containerId}`, containerId)
} }
editorInstance.cm.on('change', (cm) => { //当光标或选中内容时触发绑定@事件
if(forMember){ editorInstance.cm.on("cursorActivity", () => {
if (forMember) {
document.onkeydown = (e) => { document.onkeydown = (e) => {
console.log('onkeydown', e)
if (e.key === "@") { if (e.key === "@") {
// 输入@键后在对应的位置显示可选的项目成员 // 输入@键后在对应的位置显示可选的项目成员
// const endOffset = window.getSelection();
setAtWhoVisible(true); setAtWhoVisible(true);
// const addValue = atWho? cm.getValue()+atWho:cm.getValue(); } else {
// onChange(addValue);
}else{
setAtWhoVisible(false); setAtWhoVisible(false);
} }
}; };
} }
console.log('change---') });
editorInstance.cm.on("change", (cm) => {
onChange && onChange(cm.getValue()); onChange && onChange(cm.getValue());
// atWho && onChange(addValue+atWho) && setAtWho(undefined); });
// if(atWho){
// onChange(cm.getValue()+atWho);
// setAtWho(undefined);
// }else{
// onChange(cm.getValue());
// }
})
if (onChange) { if (onChange) {
} }
ro = onLayout() ro = onLayout()