Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/modules/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@
}
}
} catch (e) {
console.log("[updateCell] spill failed; falling back", e);

Check warning on line 1222 in packages/core/src/modules/cell.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 1222 in packages/core/src/modules/cell.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
}

// --- hyperlink-on-edit-paste support ---
Expand Down Expand Up @@ -1586,7 +1586,7 @@
// style += "font-family: " + f + ";";
// }

if (key === "fs" && valueNum !== 10) {
if (key === "fs" && !_.isNil(value)) {
style.fontSize = `${valueNum}pt`;
}

Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/modules/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,8 @@ export function rangeValueToHtml(
const c = colIndexArr[j];

// eslint-disable-next-line no-template-curly-in-string
let column = '<td ${span} style="${style}">';
let column =
'<td ${span} style="${style}" data-fortune-cell="${cellData}">';

const cell = d[r]?.[c];
if (cell != null) {
Expand Down Expand Up @@ -1903,7 +1904,10 @@ export function rangeValueToHtml(
}
}

column = replaceHtml(column, { style, span });
const cellData = encodeURIComponent(
JSON.stringify({ ...cell, _srcRow: r, _srcCol: c })
);
column = replaceHtml(column, { style, span, cellData });

if (_.isNil(c_value)) {
c_value = getCellValue(r, c, d);
Expand Down Expand Up @@ -1994,7 +1998,7 @@ export function rangeValueToHtml(
}
}

column = replaceHtml(column, { style, span: "" });
column = replaceHtml(column, { style, span: "", cellData: "" });
column += "";
}

Expand Down
48 changes: 43 additions & 5 deletions packages/core/src/paste-table-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getQKBorder, saveHyperlink } from "./modules";
import { Cell } from "./types";
import { getSheetIndex } from "./utils";
import { setRowHeight, setColumnWidth } from "./api";
import { adjustFormulaForPaste } from "./events/paste";

export const DEFAULT_FONT_SIZE = 12;

Expand Down Expand Up @@ -150,6 +151,8 @@ interface BuiltCellResult {
rowspan: number;
colspan: number;
hyperlink?: { href: string; display: string } | null;
srcRow?: number;
srcCol?: number;
}

const HEX_REGEX = /^0x?[a-fA-F0-9]+$/;
Expand Down Expand Up @@ -177,6 +180,30 @@ const buildCellFromTd = (
classStyles: Record<string, string>,
ctx: Context
): BuiltCellResult => {
const fortuneCellAttr = td.getAttribute("data-fortune-cell");
if (fortuneCellAttr) {
try {
const { _srcRow, _srcCol, ...parsed } = JSON.parse(
decodeURIComponent(fortuneCellAttr)
);
const cell = parsed as Cell;
delete cell.mc;
delete cell.hl;
const rowspan = parseInt(td.getAttribute("rowspan") || "1", 10);
const colspan = parseInt(td.getAttribute("colspan") || "1", 10);
return {
cell,
rowspan: Number.isNaN(rowspan) ? 1 : rowspan,
colspan: Number.isNaN(colspan) ? 1 : colspan,
hyperlink: detectHyperlink(td),
srcRow: _srcRow,
srcCol: _srcCol,
};
} catch {
// fall through to CSS parsing if JSON is malformed
}
}

let cell: Cell = {};
const rawText = (td.innerText || td.innerHTML || "").trim();
const isLineBreak = rawText.includes("<br />");
Expand Down Expand Up @@ -391,16 +418,27 @@ export function handlePastedTable(
}
if (localColIndex === totalColumns) return; // row overflow

const { cell, rowspan, colspan, hyperlink } = buildCellFromTd(
tdElement,
classStyleMap,
ctx
);
const { cell, rowspan, colspan, hyperlink, srcRow, srcCol } =
buildCellFromTd(tdElement, classStyleMap, ctx);

const anchorCol = ctx.luckysheet_select_save![0].column[0];
const absoluteRow = anchorRow + localRowIndex;
const absoluteCol = anchorCol + localColIndex;

if (cell.f && srcRow != null && srcCol != null) {
try {
cell.f = adjustFormulaForPaste(
cell.f,
srcCol,
srcRow,
absoluteCol,
absoluteRow
);
} catch {
// invalid ref — leave formula as-is
}
}

// Place cell into matrix
pastedMatrix[localRowIndex][localColIndex] = cell;

Expand Down
Loading