From c26c1662955f7e470ca2eff9fc9e074228e3cc99 Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 27 Jul 2023 15:54:36 +0300 Subject: [PATCH] Fixed bugs in Chrome browser Fixed on load data config listeners reassigning --- src/components/sheet.ts | 5 +++-- src/main.ts | 10 +++++++--- src/modules/cache.ts | 12 ++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/components/sheet.ts b/src/components/sheet.ts index 18cfab3..1c5530a 100644 --- a/src/components/sheet.ts +++ b/src/components/sheet.ts @@ -103,10 +103,10 @@ export class Sheet { height: number, ) { this.ctx.save(); - this.ctx.strokeStyle = "#47d1ff"; + this.ctx.strokeStyle = "#7da8ff"; this.ctx.lineWidth = 3; this.ctx.strokeRect(x, y, width, height); - this.ctx.fillStyle = "#7da8ff50"; + this.ctx.fillStyle = "#7da8ff35"; this.ctx.fillRect(x, y, width, height); this.ctx.restore(); } @@ -124,6 +124,7 @@ export class Sheet { const lastRowIdx = this.root.viewport.lastRow + 3; const firstColIdx = this.root.viewport.firstCol; + for (let row = firstRowIdx; row <= lastRowIdx; row++) { for (let col = firstColIdx; col <= lastColIdx; col++) { if (!this.root.config.columns[col] || !this.root.config.rows[row]) diff --git a/src/main.ts b/src/main.ts index 1c2d7fd..b58296b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -331,7 +331,6 @@ export default class Spreadsheet { public loadData(data: Cell[][] | SerializableCell[][]): Spreadsheet { const rowsLength = data.length; const colsLength = data[0] ? data[0].length : 0; - console.log("!!FORMATTED DATA", rowsLength, colsLength, data[0]) this.data = []; const formattedData: Cell[][] = []; @@ -353,12 +352,17 @@ export default class Spreadsheet { formattedData.push(innerRow); } + const config = this.makeConfigFromData(formattedData, this.config.view); + config.onCellChange = this.config.onCellChange + config.onCellClick = this.config.onCellClick + config.onCopy = this.config.onCopy + config.onSelectonChange = this.config.onSelectonChange + this.data = formattedData; - this.selection.selectedCell = null; this.selection.selectedRange = null; - this.config = this.makeConfigFromData(formattedData, this.config.view); + this.config = config this.cache = this.getInitialCache(); this.scroller.updateScrollerSize(); this.viewport = new Viewport( diff --git a/src/modules/cache.ts b/src/modules/cache.ts index 9120f0a..c7e5145 100644 --- a/src/modules/cache.ts +++ b/src/modules/cache.ts @@ -44,21 +44,21 @@ export class Cache { public getRowByYCoord(y: number): number { let rowIdx = 0; for (let i = 0; i < this.rows.length; i++) { - if (y <= this.rows[i].yPos) { - //* Intersection detect - rowIdx = i; + rowIdx = i + if (y <= this.rows[i].yPos) { //* Intersection detect break; } + } + return rowIdx; } public getColumnByXCoord(x: number): number { let colIdx = 0; for (let i = 0; i < this.columns.length; i++) { - if (x <= this.columns[i].xPos) { - //* Intersection detect - colIdx = i; + colIdx = i + if (x <= this.columns[i].xPos) { //* Intersection detect break; } }