fix: change count of col/row after col/row deleted and test function

This commit is contained in:
gazedreamily 2023-02-03 13:19:49 +08:00 committed by Qaplagzy
parent a24826a184
commit f070c71642
7 changed files with 40 additions and 21 deletions

View File

@ -11500,6 +11500,8 @@ export default {
generateNewMatrix: "Generate new matrix",
noMulti:
"Cannot perform this operation on multiple selection areas, please select a single area",
cannotDeleteAllRow: "Cannot delete all rows",
cannotDeleteAllColumn: "Cannot delete all columns",
},
comment: {
insert: "Insert",

View File

@ -11475,6 +11475,8 @@ export default {
generateNewMatrix: "Generar nueva matriz",
noMulti:
"No se puede realizar esta operación en varias áreas de selección, selecciona una sola área",
cannotDeleteAllRow: "No se pueden eliminar todas las filas",
cannotDeleteAllColumn: "No se pueden eliminar todas las columnas",
},
comment: {
insert: "Insertar",

View File

@ -11534,6 +11534,8 @@ export default {
byCol: "按列",
generateNewMatrix: "生成新矩阵",
noMulti: "无法对多重选择区域执行此操作,请选择单个区域",
cannotDeleteAllRow: "无法删除所有行",
cannotDeleteAllColumn: "无法删除所有列",
},
comment: {
insert: "新建批注",

View File

@ -11504,6 +11504,8 @@ export default {
byCol: "按列",
generateNewMatrix: "生成新矩陣",
noMulti: "無法對多重選擇區域執行此操作,請選擇單個區域",
cannotDeleteAllRow: "無法刪除所有行",
cannotDeleteAllColumn: "無法刪除所有列",
},
comment: {
insert: "新建批註",

View File

@ -1713,14 +1713,8 @@ export function deleteRowCol(
// 删除选中行
d.splice(start, slen);
// 删除多少行,增加多少行空白行
for (let r = 0; r < slen; r += 1) {
const row = [];
for (let c = 0; c < d[0].length; c += 1) {
row.push(null);
}
d.push(row);
}
// 删除行后,调整行数
file.row! -= slen;
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type1 = "c";
@ -1818,20 +1812,13 @@ export function deleteRowCol(
cfg.borderInfo = borderInfo;
}
// 空白列模板
const addcol = [];
for (let r = 0; r < slen; r += 1) {
addcol.push(null);
}
for (let r = 0; r < d.length; r += 1) {
const row = _.clone(d[r]);
// 删除选中列
row.splice(start, slen);
d[r] = row.concat(addcol);
d[r].splice(start, slen);
}
// 删除列后,调整列数
file.column! -= slen;
}
// 修改当前sheet页时刷新

View File

@ -97,9 +97,10 @@ describe("rowcol", () => {
{ type: "column", start: 1, end: 1, rawData: rawDataSecond },
].forEach((k) => {
ctx.luckysheetfile[0].data = k.rawData();
const slen = k.end - k.start + 1;
deleteRowOrColumn(ctx, k.type, k.start, k.end);
_.range(0, k.rawData().length).forEach((i) => {
_.range(0, k.rawData()[0].length).forEach((j) => {
_.range(0, k.rawData().length - slen).forEach((i) => {
_.range(0, k.rawData()[0].length - slen).forEach((j) => {
let expectedValue;
if (k.type === "row") {
expectedValue = () => {

View File

@ -12,6 +12,7 @@ import {
handleLink,
hideSelected,
showSelected,
getSheetIndex,
} from "@fortune-sheet/core";
import _ from "lodash";
import React, { useContext, useRef, useLayoutEffect, useCallback } from "react";
@ -225,6 +226,18 @@ const ContextMenu: React.FC = () => {
draftCtx.contextMenu = undefined;
return;
}
const slen = ed_index - st_index + 1;
const index = getSheetIndex(
draftCtx,
context.currentSheetId
) as number;
if (
draftCtx.luckysheetfile[index].data?.[0]?.length! <= slen
) {
showAlert(rightclick.cannotDeleteAllColumn, "ok");
draftCtx.contextMenu = undefined;
return;
}
deleteRowCol(draftCtx, deleteRowColOp);
draftCtx.contextMenu = undefined;
},
@ -257,6 +270,16 @@ const ContextMenu: React.FC = () => {
draftCtx.contextMenu = undefined;
return;
}
const slen = ed_index - st_index + 1;
const index = getSheetIndex(
draftCtx,
context.currentSheetId
) as number;
if (draftCtx.luckysheetfile[index].data?.length! <= slen) {
showAlert(rightclick.cannotDeleteAllRow, "ok");
draftCtx.contextMenu = undefined;
return;
}
deleteRowCol(draftCtx, deleteRowColOp);
draftCtx.contextMenu = undefined;
},