|
@@ -345,6 +345,7 @@ export const setSearch = (state,action)=>{
|
|
|
let searchData = action.data;
|
|
|
res.searchDatas = searchData;
|
|
|
res.searchStr = action.inpStr;
|
|
|
+ res.isEnd = action.isEnd;
|
|
|
return res;
|
|
|
}
|
|
|
|
|
@@ -406,25 +407,29 @@ export const insertSearch = (state,action)=>{
|
|
|
|
|
|
// 从新插入一个span标签
|
|
|
const searchStr = res.searchStr;
|
|
|
+ const isEnd = res.isEnd;
|
|
|
let innerText = span.current.innerText || span.current.innerHTML;
|
|
|
- const value = innerText.replace(searchStr,"");
|
|
|
- let index = innerText.indexOf(searchStr);
|
|
|
- if(index < 1){//前
|
|
|
- if(data[focusIndex].value==searchStr){//为空标签则替换
|
|
|
+ if(!isEnd){//前
|
|
|
+ const reg = new RegExp("^"+searchStr)
|
|
|
+ const value = innerText.replace(reg,"");
|
|
|
+ res.data.splice(focusIndex,0,nText);
|
|
|
+ res.saveText.splice(focusIndex,0,searchData);
|
|
|
+ res.data[focusIndex+1].value = value;
|
|
|
+ res.saveText[focusIndex+1] = value;
|
|
|
+ span.current.innerText?(span.current.innerText = value):(span.current.innerHTML=value);
|
|
|
+ }else{
|
|
|
+ const reg = new RegExp(searchStr+"$")
|
|
|
+ const value = innerText.replace(reg,"");
|
|
|
+ if(data[focusIndex].value.trim()==searchStr){//为空标签则替换-否则会多一个空标签
|
|
|
res.data.splice(focusIndex,1,nText);
|
|
|
res.saveText.splice(focusIndex,1,searchData);
|
|
|
}else{
|
|
|
- res.data.splice(focusIndex,0,nText);
|
|
|
- res.saveText.splice(focusIndex,0,searchData);
|
|
|
- res.data[focusIndex+1].value = value;
|
|
|
- res.saveText[focusIndex+1] = value;
|
|
|
- }
|
|
|
- }else{
|
|
|
- res.data.splice(focusIndex+1,0,nText);
|
|
|
- res.saveText.splice(focusIndex+1,0,searchData);
|
|
|
- res.data[focusIndex].value = value;
|
|
|
- }
|
|
|
- span.current.innerText?(span.current.innerText = value):(span.current.innerHTML=value);
|
|
|
+ res.data.splice(focusIndex+1,0,nText);
|
|
|
+ res.saveText.splice(focusIndex+1,0,searchData);
|
|
|
+ res.data[focusIndex].value = value;
|
|
|
+ }
|
|
|
+ span.current.innerText?(span.current.innerText = value):(span.current.innerHTML=value);
|
|
|
+ }
|
|
|
res.mainIds.push(ids);
|
|
|
if(id){
|
|
|
res.mainTailIds.push(id);
|