From 3b377617b3aee791630f93dee642caa07fb9f968 Mon Sep 17 00:00:00 2001 From: wbfsa Date: Thu, 4 Mar 2021 02:54:07 +0800 Subject: [PATCH] fix: Find&Replace also replaces in locked cells --- src/controllers/protection.js | 4 ++-- src/controllers/searchReplace.js | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/controllers/protection.js b/src/controllers/protection.js index d3124a0..c7783a5 100644 --- a/src/controllers/protection.js +++ b/src/controllers/protection.js @@ -892,7 +892,7 @@ export function checkProtectionNotEnable(sheetIndex){ } //cell locked state -export function checkProtectionLocked(r, c, sheetIndex){ +export function checkProtectionLocked(r, c, sheetIndex, isOpenAlert=true, isLock=true){ let sheetFile = sheetmanage.getSheetByIndex(sheetIndex); if(sheetFile==null){ @@ -916,7 +916,7 @@ export function checkProtectionLocked(r, c, sheetIndex){ const _locale = locale(); const local_protection = _locale.protection; - return checkProtectionLockedSqref(r, c , aut, local_protection); + return checkProtectionLockedSqref(r, c , aut, local_protection, isOpenAlert, isLock); } //cell hidden state diff --git a/src/controllers/searchReplace.js b/src/controllers/searchReplace.js index 666d43e..fe80d42 100644 --- a/src/controllers/searchReplace.js +++ b/src/controllers/searchReplace.js @@ -12,6 +12,8 @@ import tooltip from '../global/tooltip'; import func_methods from '../global/func_methods'; import Store from '../store'; import locale from '../locale/locale'; +import {checkProtectionLockedRangeList,checkProtectionAllSelected,checkProtectionSelectLockedOrUnLockedCells,checkProtectionNotEnable,checkProtectionLocked} from './protection'; + //查找替换 const luckysheetSearchReplace = { @@ -575,6 +577,10 @@ const luckysheetSearchReplace = { let v = replaceText; + if(!checkProtectionLocked(r, c, Store.currentSheetIndex)){ + return; + } + setcellvalue(r, c, d, v); } else{ @@ -589,6 +595,10 @@ const luckysheetSearchReplace = { r = searchIndexArr[count].r; c = searchIndexArr[count].c; + if(!checkProtectionLocked(r, c, Store.currentSheetIndex)){ + return; + } + let v = valueShowEs(r, c, d).toString().replace(reg, replaceText); setcellvalue(r, c, d, v); @@ -695,17 +705,22 @@ const luckysheetSearchReplace = { let replaceText = $("#luckysheet-search-replace #replaceInput input").val(); let d = editor.deepCopyFlowData(Store.flowdata); - + let replaceCount = 0; if(wordCheck){ for(let i = 0; i < searchIndexArr.length; i++){ let r = searchIndexArr[i].r; let c = searchIndexArr[i].c; + if(!checkProtectionLocked(r, c, Store.currentSheetIndex, false)){ + continue; + } + let v = replaceText; setcellvalue(r, c, d, v); range.push({ "row": [r, r], "column": [c, c] }); + replaceCount++; } } else{ @@ -721,11 +736,16 @@ const luckysheetSearchReplace = { let r = searchIndexArr[i].r; let c = searchIndexArr[i].c; + if(!checkProtectionLocked(r, c, Store.currentSheetIndex, false)){ + continue; + } + let v = valueShowEs(r, c, d).toString().replace(reg, replaceText); setcellvalue(r, c, d, v); range.push({ "row": [r, r], "column": [c, c] }); + replaceCount++; } } @@ -739,7 +759,7 @@ const luckysheetSearchReplace = { selectHightlightShow(); let succeedInfo = replaceHtml(locale_findAndReplace.successTip, { - "xlength": searchIndexArr.length + "xlength": replaceCount }); if(isEditMode()){ alert(succeedInfo);