diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js index 820bb10..16fc31f 100644 --- a/src/controllers/menuButton.js +++ b/src/controllers/menuButton.js @@ -37,6 +37,7 @@ import { replaceHtml, getObjType, rgbTohex, mouseclickposition, luckysheetfontfo import {openProtectionModal,checkProtectionFormatCells,checkProtectionNotEnable} from './protection'; import Store from '../store'; import locale from '../locale/locale'; +import {checkTheStatusOfTheSelectedCells} from '../global/api'; const menuButton = { "menu": '
', @@ -2171,19 +2172,11 @@ const menuButton = { e.stopPropagation(); }).click(function(e){ let d = editor.deepCopyFlowData(Store.flowdata); - let row_index = Store.luckysheet_select_save[0]["row_focus"], - col_index = Store.luckysheet_select_save[0]["column_focus"]; - let foucsStatus = _this.checkstatus(d, row_index, col_index, "bl"); - - if(foucsStatus == 1){ - foucsStatus = 0; - } - else{ - foucsStatus = 1; - } + + let flag = checkTheStatusOfTheSelectedCells("bl",1); + let foucsStatus = flag ? 0 : 1; _this.updateFormat(d, "bl", foucsStatus); - _this.menuButtonFocus(d, row_index, col_index); }); //斜体 @@ -2192,19 +2185,11 @@ const menuButton = { e.stopPropagation(); }).click(function(){ let d = editor.deepCopyFlowData(Store.flowdata); - let row_index = Store.luckysheet_select_save[0]["row_focus"], - col_index = Store.luckysheet_select_save[0]["column_focus"]; - let foucsStatus = _this.checkstatus(d, row_index, col_index, "it"); - if(foucsStatus == 1){ - foucsStatus = 0; - } - else{ - foucsStatus = 1; - } + let flag = checkTheStatusOfTheSelectedCells("it",1); + let foucsStatus = flag ? 0 : 1; _this.updateFormat(d, "it", foucsStatus); - _this.menuButtonFocus(d, row_index, col_index); }); //删除线 @@ -2213,19 +2198,10 @@ const menuButton = { e.stopPropagation(); }).click(function(){ let d = editor.deepCopyFlowData(Store.flowdata); - let row_index = Store.luckysheet_select_save[0]["row_focus"], - col_index = Store.luckysheet_select_save[0]["column_focus"]; - let foucsStatus = _this.checkstatus(d, row_index, col_index, "cl"); - - if(foucsStatus == 1){ - foucsStatus = 0; - } - else{ - foucsStatus = 1; - } + let flag = checkTheStatusOfTheSelectedCells("cl",1); + let foucsStatus = flag ? 0 : 1; _this.updateFormat(d, "cl", foucsStatus); - _this.menuButtonFocus(d, row_index, col_index); }); //下划线 @@ -2234,19 +2210,10 @@ const menuButton = { e.stopPropagation(); }).click(function(){ let d = editor.deepCopyFlowData(Store.flowdata); - let row_index = Store.luckysheet_select_save[0]["row_focus"], - col_index = Store.luckysheet_select_save[0]["column_focus"]; - let foucsStatus = _this.checkstatus(d, row_index, col_index, "un"); - - if(foucsStatus == 1){ - foucsStatus = 0; - } - else{ - foucsStatus = 1; - } + let flag = checkTheStatusOfTheSelectedCells("un",1); + let foucsStatus = flag ? 0 : 1; _this.updateFormat(d, "un", foucsStatus); - _this.menuButtonFocus(d, row_index, col_index); }); //条件格式 diff --git a/src/global/api.js b/src/global/api.js index 549dfdb..17c6628 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -6680,6 +6680,9 @@ export function checkTheStatusOfTheSelectedCells(type,status){ let flag = cells.every(({r,c})=>{ let cell = Store.flowdata[r][c]; + if(cell == null){ + return false; + } return cell[type] == status; })