Skip to content

Commit

Permalink
Merge pull request #612 from Corbe30/bugfix/filtered-rows-copied
Browse files Browse the repository at this point in the history
#605 fixed: copy ignores hidden rows, columns in all cases + linter issues
  • Loading branch information
sanchit3008 authored Oct 17, 2024
2 parents 3e20be4 + 10478d9 commit b441c81
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
13 changes: 4 additions & 9 deletions packages/core/src/events/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,11 +1100,6 @@ function pasteHandlerOfCopyPaste(
const c_c1 = copyRange.copyRange[0].column[0];
const c_c2 = copyRange.copyRange[0].column[1];

const isSingleCellPaste =
copyRange.copyRange.length === 1 &&
copyRange.copyRange[0].row[0] === copyRange.copyRange[0].row[1] &&
copyRange.copyRange[0].column[0] === copyRange.copyRange[0].column[1];

let arr: CellMatrix = [];
let isSameRow = false;
for (let i = 0; i < copyRange.copyRange.length; i += 1) {
Expand Down Expand Up @@ -1231,9 +1226,8 @@ function pasteHandlerOfCopyPaste(
let maxrowCache = 0;

const file = ctx.luckysheetfile[getSheetIndex(ctx, ctx.currentSheetId)!];
let hiddenRows;
if (isSingleCellPaste)
hiddenRows = new Set(Object.keys(file.config?.rowhidden || {}));
const hiddenRows = new Set(Object.keys(file.config?.rowhidden || {}));
const hiddenCols = new Set(Object.keys(file.config?.colhidden || {}));

for (let th = 1; th <= timesH; th += 1) {
for (let tc = 1; tc <= timesC; tc += 1) {
Expand All @@ -1249,10 +1243,11 @@ function pasteHandlerOfCopyPaste(
const offsetMC: any = {};
for (let h = mth; h < maxrowCache; h += 1) {
// skip if row is hidden
if (isSingleCellPaste && hiddenRows?.has(h.toString())) continue;
if (hiddenRows?.has(h.toString())) continue;
const x = d[h];

for (let c = mtc; c < maxcellCahe; c += 1) {
if (hiddenCols?.has(c.toString())) continue;
if (
borderInfoCompute[`${c_r1 + h - mth}_${c_c1 + c - mtc}`] &&
!borderInfoCompute[`${c_r1 + h - mth}_${c_c1 + c - mtc}`].s
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/modules/dropCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,7 @@ export function updateDropCell(ctx: Context) {
if (index == null) return;
const file = ctx.luckysheetfile[index];
const hiddenRows = new Set(Object.keys(file.config?.rowhidden || {}));
const hiddenCols = new Set(Object.keys(file.config?.colhidden || {}));

const cfg = _.cloneDeep(ctx.config);
if (cfg.borderInfo == null) {
Expand Down Expand Up @@ -2332,6 +2333,7 @@ export function updateDropCell(ctx: Context) {
const asLen = apply_end_r - apply_str_r + 1;

for (let i = apply_str_c; i <= apply_end_c; i += 1) {
if (hiddenCols.has(`${i}`)) continue;
const copyD = copyData[i - apply_str_c];

const applyData = getApplyData(copyD, csLen, asLen);
Expand Down Expand Up @@ -2559,6 +2561,7 @@ export function updateDropCell(ctx: Context) {

if (direction === "right") {
for (let j = apply_str_c; j <= apply_end_c; j += 1) {
if (hiddenCols.has(`${j}`)) continue;
const cell = applyData[j - apply_str_c];

if (cell?.f != null) {
Expand Down Expand Up @@ -2657,6 +2660,7 @@ export function updateDropCell(ctx: Context) {
}
if (direction === "left") {
for (let j = apply_end_c; j >= apply_str_c; j -= 1) {
if (hiddenCols.has(`${j}`)) continue;
const cell = applyData[apply_end_c - j];

if (cell?.f != null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/ContextMenu/FilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const FilterMenu: React.FC = () => {
}
_.set(draftCtx, "filterContextMenu.listBoxMaxHeight", containerH);
});
}, [filterContextMenu, setContext]);
}, [filterContextMenu, refs.workbookContainer, setContext]);

useLayoutEffect(() => {
if (!subMenuPos) return;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/ContextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ const ContextMenu: React.FC = () => {
draftCtx.contextMenu.y = top;
});
}
}, [contextMenu.x, contextMenu.y, setContext]);
}, [contextMenu.x, contextMenu.y, refs.workbookContainer, setContext]);

if (_.isEmpty(context.contextMenu)) return null;

Expand Down
13 changes: 2 additions & 11 deletions packages/react/src/components/FilterOption/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import React, { useCallback, useContext, useEffect } from "react";
import WorkbookContext from "../../context";
import SVGIcon from "../SVGIcon";

const FilterOptions: React.FC<{ getContainer: () => HTMLDivElement }> = ({
getContainer,
}) => {
const FilterOptions: React.FC<{}> = () => {
const { context, setContext, refs } = useContext(WorkbookContext);
const {
filterOptions,
Expand Down Expand Up @@ -77,14 +75,7 @@ const FilterOptions: React.FC<{ getContainer: () => HTMLDivElement }> = ({
};
});
},
[
filterOptions,
getContainer,
refs.scrollbarX,
refs.scrollbarY,
refs.workbookContainer,
setContext,
]
[filterOptions, refs.scrollbarX, refs.scrollbarY, setContext]
);

const freezeType = frozen?.type;
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Workbook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ const Workbook = React.forwardRef<WorkbookInstance, Settings & AdditionalProps>(
mergedSettings.rowHeaderWidth,
mergedSettings.columnHeaderHeight,
mergedSettings.addRows,
mergedSettings.currency,
]);

const onKeyDown = useCallback(
Expand Down

0 comments on commit b441c81

Please sign in to comment.