Skip to content
Merged
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
11 changes: 7 additions & 4 deletions src/ui/panels/Artifact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ function colsOf(art: Art): string[] {

function sheetElementId(art: Art, rowId: string, colId: string): string {
const numericRow = rowId.match(/^r?(\d+)$/)?.[1] ?? rowId;
const a1 = `${colId}${numericRow}`;
const a1 = `${/^[A-Za-z]+$/.test(colId) ? colId.toUpperCase() : colId}${numericRow}`;
if (art.meta?.excelGrid) return a1;
if (isBlankSpreadsheet(art)) {
// Prefer a canonical NodeAgent write when it exists, then preserve edits
Expand All @@ -1280,8 +1280,11 @@ function sheetElementId(art: Art, rowId: string, colId: string): string {
function parseSheetElementId(art: Art, elementId: string | null): { rowId: string; colId: string } {
if (!elementId) return { rowId: "", colId: "" };
if (art.meta?.excelGrid || isBlankSpreadsheet(art)) {
const match = elementId.match(/^([A-Z]+)(\d+)$/);
if (match) return { colId: match[1], rowId: match[2] };
const match = elementId.match(/^([A-Za-z]+)(\d+)$/);
if (match) {
const metaCol = art.meta?.dataframe?.columns?.find((col) => col.id.toUpperCase() === match[1].toUpperCase())?.id;
return { colId: metaCol ?? match[1], rowId: match[2] };
}
const legacy = elementId.match(/^r?(\d+)__(.+)$/);
if (legacy) return { rowId: legacy[1], colId: legacy[2] };
return { rowId: "", colId: "" };
Expand Down Expand Up @@ -1325,7 +1328,7 @@ function sheetColumnWidth(art: Art, col: DataframeColumn, index: number): number

function dataframeCellAddress(art: Art, cols: string[], rows: string[], key: string | null): string {
if (!key) return "";
if (art.meta?.excelGrid || (isBlankSpreadsheet(art) && /^[A-Z]+\d+$/.test(key))) return key;
if (art.meta?.excelGrid || (isBlankSpreadsheet(art) && /^[A-Za-z]+\d+$/.test(key))) return key.toUpperCase();
const sep = key.indexOf("__");
if (sep < 0) return "";
const rowId = key.slice(0, sep);
Expand Down
10 changes: 5 additions & 5 deletions tests/sheetVirtualization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function renderScaleSheet(art: Art) {
}

function makeMixedAddressBlankSheet(order: string[] = []): Art {
const columns: DataframeColumn[] = ["A", "B", "C", "D"].map((id, index) => ({
const columns: DataframeColumn[] = ["a", "b", "c", "d"].map((id, index) => ({
id,
label: id,
order: index,
Expand All @@ -206,8 +206,8 @@ function makeMixedAddressBlankSheet(order: string[] = []): Art {
version: 23,
order,
elements: {
r2__B: { value: 10_000, version: 1, updatedAt: 1_000, updatedBy: PRIYA },
r3__B: { value: 4_000, version: 1, updatedAt: 1_000, updatedBy: PRIYA },
r2__b: { value: 10_000, version: 1, updatedAt: 1_000, updatedBy: PRIYA },
r3__b: { value: 4_000, version: 1, updatedAt: 1_000, updatedBy: PRIYA },
B4: { value: "=B2-B3", version: 1, updatedAt: 2_000, updatedBy: { kind: "agent", id: "room", name: "Room NodeAgent" } },
D4: { value: "=C4-B4", version: 1, updatedAt: 2_000, updatedBy: { kind: "agent", id: "room", name: "Room NodeAgent" } },
},
Expand Down Expand Up @@ -235,9 +235,9 @@ describe("GenericSheet blank-room A1 compatibility", () => {
});

it("prefers a canonical NodeAgent A1 write while preserving legacy seed values", () => {
const legacyOrder = ["r2__B", "r3__B", "r4__B", "r4__D"];
const legacyOrder = ["r2__b", "r3__b", "r4__b", "r4__d"];
const { container } = renderScaleSheet(makeMixedAddressBlankSheet(legacyOrder));
expect(container.querySelector('[data-element-id="r2__B"]')?.textContent).toContain("10000");
expect(container.querySelector('[data-element-id="r2__b"]')?.textContent).toContain("10000");
expect(container.querySelector('[data-element-id="B4"]')?.textContent).toContain("=B2-B3");
});
});
Expand Down
Loading