forked from Gitlink/forgeplus-react
at谁列表(缺弹框的上下,enter键监听)
This commit is contained in:
parent
18b289b84c
commit
4f3e385f78
|
@ -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,56 +260,30 @@ 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,"");
|
||||
})
|
||||
console.log('剔除初始内容中的@who',value);
|
||||
}
|
||||
//以username为主键,login为value的map集合
|
||||
let atWhoMap = new Map();
|
||||
Array.from(atWhoLoginList.current).map(item=>{
|
||||
users.map(i=>{
|
||||
if(i.login === item){
|
||||
atWhoMap.set(i.username,i.login);
|
||||
}
|
||||
})
|
||||
});
|
||||
if(value.indexOf("@") === -1){
|
||||
//已经有要@的列表,但是没有@符号 -> 清空@集合
|
||||
atWhoLoginList.current = [];
|
||||
setAtWhoLoginListState([]);
|
||||
return;
|
||||
}
|
||||
const cursor = codemirror.doc.getCursor();
|
||||
const line = cursor.line;
|
||||
const ch = cursor.ch;
|
||||
const lineContent = codemirror.getLine(line);
|
||||
if(lineContent && lineContent.indexOf("@") != -1){//此行有@谁
|
||||
Array.from(atWhoMap.keys()).map(username=>{
|
||||
//判断lineContent是不是以列表中的某个username结尾
|
||||
if(lineContent.endsWith(username)){
|
||||
codemirror.setSelection({line,ch:ch-username.length-1},{line,ch});
|
||||
return;
|
||||
}
|
||||
//处理有名字但是无@符号,有@但是名字对不上的情况
|
||||
if(value.indexOf(username)===-1 || value.charAt(value.indexOf(username)-1) !="@"){
|
||||
//符合任意一种情况->踢掉这个人 不给他发消息
|
||||
//判断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.delete(atWhoMap.get(username));
|
||||
list.add(item.login);
|
||||
atWhoLoginList.current = Array.from(list);
|
||||
setAtWhoLoginListState(Array.from(list));
|
||||
}
|
||||
|
@ -324,6 +297,62 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
|
|||
});
|
||||
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();
|
||||
Array.from(atWhoLoginList.current).map(item=>{
|
||||
users.map(i=>{
|
||||
if(i.login === item){
|
||||
atWhoMap.set(i.username,i.login);
|
||||
}
|
||||
})
|
||||
});
|
||||
if(value.indexOf("@") === -1){
|
||||
//已经有要@的列表,但是没有@符号 -> 清空@集合
|
||||
atWhoLoginList.current = [];
|
||||
setAtWhoLoginListState([]);
|
||||
return;
|
||||
}
|
||||
const cursor = codemirror.doc.getCursor();
|
||||
const line = cursor.line;
|
||||
const ch = cursor.ch;
|
||||
const lineContent = codemirror.getLine(line);
|
||||
if(lineContent && lineContent.indexOf("@") != -1){//此行有@谁
|
||||
Array.from(atWhoMap.keys()).map(username=>{
|
||||
//判断lineContent是不是以列表中的某个username结尾
|
||||
if(lineContent.endsWith(username)){
|
||||
codemirror.setSelection({line,ch:ch-username.length-1},{line,ch});
|
||||
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);
|
||||
list.delete(atWhoMap.get(username));
|
||||
atWhoLoginList.current = Array.from(list);
|
||||
setAtWhoLoginListState(Array.from(list));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
ro = onLayout()
|
||||
return () => {
|
||||
|
|
Loading…
Reference in New Issue