Skip to content

Commit

Permalink
[FIX] clipboard: cut & paste bad expression with references
Browse files Browse the repository at this point in the history
Task: 0
Part-of: #4053
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Co-authored-by: Rachico <[email protected]>
  • Loading branch information
LucasLefevre and Rachico committed Aug 5, 2024
1 parent 635739e commit 6b26d71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugins/core/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
dependencies: Range[],
useFixedReference: boolean = false
): string {
if (!dependencies.length) {
return concat(compiledFormula.tokens.map((token) => token.value));
}
let rangeIndex = 0;
return concat(
compiledFormula.tokens.map((token) => {
Expand Down
12 changes: 12 additions & 0 deletions tests/clipboard/clipboard_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,18 @@ describe("clipboard", () => {
});
});

test("can cut and paste an invalid formula", () => {
const model = new Model();
setCellContent(model, "A1", "=(+)");
setCellContent(model, "A2", "=C1{C2");
cut(model, "A1:A2");
paste(model, "C1");
expect(getCellText(model, "C1")).toBe("=(+)");
expect(getCellText(model, "C2")).toBe("=C1{C2");
expect(getCellText(model, "A1")).toBe("");
expect(getCellText(model, "A2")).toBe("");
});

test("cut/paste a formula with references does not update references in the formula", () => {
const model = new Model();
setCellContent(model, "A1", "=SUM(C1:C2)");
Expand Down

0 comments on commit 6b26d71

Please sign in to comment.