From 9f0b746c070c3a656f20df8ab46498a72469bf59 Mon Sep 17 00:00:00 2001 From: Leoo <42474033+xXLeoXxOne@users.noreply.github.com> Date: Mon, 5 Jan 2026 13:18:07 +0100 Subject: [PATCH 1/2] Refactor to use reduce for max column calculation --- src/CsvEditorProvider.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CsvEditorProvider.ts b/src/CsvEditorProvider.ts index 06c0c6d..e7f523c 100644 --- a/src/CsvEditorProvider.ts +++ b/src/CsvEditorProvider.ts @@ -440,7 +440,7 @@ class CsvEditorController { const text = this.document.getText(); const result = Papa.parse(text, { dynamicTyping: false, delimiter: separator }); const data = result.data as string[][]; - const numColumns = Math.max(...data.map(r => r.length), 0); + const numColumns = data.reduce((max, r) => Math.max(max, r.length), 0); const newRow = Array(numColumns).fill(''); if (index > data.length) { while (data.length < index) data.push(Array(numColumns).fill('')); @@ -466,7 +466,7 @@ class CsvEditorController { const text = this.document.getText(); const result = Papa.parse(text, { dynamicTyping: false, delimiter: separator }); const data = result.data as string[][]; - const numColumns = Math.max(...data.map(r => r.length), 0); + const numColumns = data.reduce((max, r) => Math.max(max, r.length), 0); for (let k = 0; k < count; k++) { const newRow = Array(numColumns).fill(''); if (index > data.length) { @@ -603,7 +603,7 @@ class CsvEditorController { bodyData = data.slice(offset); } const visibleForWidth = headerFlag ? [headerRow, ...bodyData] : bodyData; - let numColumns = Math.max(...visibleForWidth.map(row => row.length), 0); + let numColumns = visibleForWidth.reduce((max, row) => Math.max(max, row.length), 0); if (numColumns === 0) numColumns = 1; // ensure at least 1 column for the virtual row const columnData = Array.from({ length: numColumns }, (_, i) => bodyData.map(row => row[i] || '')); @@ -856,7 +856,7 @@ class CsvEditorController { // ───────────── Utilities ───────────── private computeColumnWidths(data: string[][]): number[] { - const numColumns = Math.max(...data.map(row => row.length), 0); + const numColumns = data.reduce((max, row) => Math.max(max, row.length), 0); const widths = Array(numColumns).fill(0); for (const row of data) { for (let i = 0; i < numColumns; i++){ From 6e2b62227c0ec21a4102ab44842f3f4d976d71f0 Mon Sep 17 00:00:00 2001 From: Leoo <42474033+xXLeoXxOne@users.noreply.github.com> Date: Mon, 5 Jan 2026 13:20:16 +0100 Subject: [PATCH 2/2] Refactor column count calculation in CsvEditorProvider --- src/CsvEditorProvider.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/CsvEditorProvider.ts b/src/CsvEditorProvider.ts index e7f523c..a582e8e 100644 --- a/src/CsvEditorProvider.ts +++ b/src/CsvEditorProvider.ts @@ -743,11 +743,7 @@ class CsvEditorController { return true; // with only one row visible, lean toward header } - const numColumns = Math.max( - headerRow.length, - ...body.map(r => r.length), - 0 - ); + const numColumns = body.reduce((max, r) => Math.max(max, r.length), Math.max(headerRow.length, 0)); const bodyColData = Array.from({ length: numColumns }, (_, i) => body.map(r => r[i] || '')); const bodyTypes = bodyColData.map(col => this.estimateColumnDataType(col)); const headerTypes = Array.from({ length: numColumns }, (_, i) => this.estimateColumnDataType([headerRow[i] || '']));