at谁列表(缺弹框的上下,enter键监听)

This commit is contained in:
谢思 2021-10-21 10:51:40 +08:00
parent 18b289b84c
commit 4f3e385f78
1 changed files with 69 additions and 40 deletions

View File

@ -118,7 +118,6 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
//替换最后的内容
cm.replaceRange(username+" ",{line,ch},{line,ch});
//将此user的login存储到atWhoLoginList集合中
atWhoLoginListState
const list = new Set(atWhoLoginList.current);
users.map((item)=>{
item.username === username && list.add(item.login);
@ -261,24 +260,58 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
} else {
setAtWhoVisible(false);
}
if(atWhoLoginList.current.length != 0){
console.log('initValue',initValue);
//处理本来@了某人 -> 删掉 -> 撤回 的情况
if(e.code === "KeyZ" && users.length != 0){
const codemirror = editorInstance.cm;
const value = codemirror.getValue();
let value = codemirror.getValue();
//处理初始内容就自带@谁的情况
if(initValue){
const del = [];
users.map(item=>{
if(initValue.indexOf(item.username)!=-1 && initValue.charAt(initValue.indexOf(item.username)-1) === "@" && initValue.indexOf(`@${item.username}`)===value.indexOf(`@${item.username}`)){
//初始内容中有符合@+名字的格式并且当前内容未删除初始内容
value.replace(`@${username}`,"");
del[del.length] = `@${item.username}`;
}
})
Array.from(atWhoMap.keys()).map(username=>{
if(initValue.indexOf(username)!=-1 && value.charAt(value.indexOf(username)-1) === "@"){
del.length!=0 && del.map(str=>{
value = value.replace(str,"");
})
}
//判断value是否包含@符号
if(value.indexOf("@") != -1){
users.map(item =>{
if(value.indexOf(item.username)!=-1 && value.charAt(value.indexOf(item.username)-1) ==="@"){
//将此user的login存储到atWhoLoginList集合中
const list = new Set(atWhoLoginList.current);
list.add(item.login);
atWhoLoginList.current = Array.from(list);
setAtWhoLoginListState(Array.from(list));
}
})
console.log('剔除初始内容中的@who',value);
}
}
};
});
editorInstance.cm.on("blur", () => {
document.onkeydown = null ;
});
editorInstance.cm.on("change", (cm) => {
onChange && onChange(cm.getValue());
if(atWhoLoginList.current.length != 0){
const codemirror = editorInstance.cm;
let value = codemirror.getValue();
//处理初始内容就自带@谁的情况
if(initValue){
const del = [];
users.map(item=>{
if(initValue.indexOf(item.username)!=-1 && initValue.charAt(initValue.indexOf(item.username)-1) === "@" && initValue.indexOf(`@${item.username}`)===value.indexOf(`@${item.username}`)){
//初始内容中有符合@+名字的格式并且当前内容未删除初始内容
del[del.length] = `@${item.username}`;
}
})
del.length!=0 && del.map(str=>{
value = value.replace(str,"");
})
}
//以username为主键login为value的map集合
let atWhoMap = new Map();
@ -307,6 +340,8 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
return;
}
//处理有名字但是无@符号,有@但是名字对不上的情况
const a = value.indexOf(username)===-1;
const b = value.charAt(value.indexOf(username)-1) !="@";
if(value.indexOf(username)===-1 || value.charAt(value.indexOf(username)-1) !="@"){
//符合任意一种情况->踢掉这个人 不给他发消息
const list = new Set(atWhoLoginList.current);
@ -317,13 +352,7 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
})
}
}
};
});
editorInstance.cm.on("blur", () => {
document.onkeydown = null ;
});
editorInstance.cm.on("change", (cm) => {
onChange && onChange(cm.getValue());
});
ro = onLayout()
return () => {