Skip to content

Commit

Permalink
Merge branch 'feat-merge-cells'
Browse files Browse the repository at this point in the history
  • Loading branch information
nusr committed Feb 23, 2024
2 parents ed73cc6 + 7edd6ea commit c49c1ba
Show file tree
Hide file tree
Showing 30 changed files with 985 additions and 504 deletions.
1 change: 0 additions & 1 deletion scripts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// esbuild hot reload
const eventSource = new EventSource('/esbuild');
eventSource.addEventListener('change', function () {
console.log('reload');
location.reload();
});
eventSource.onerror = function () {
Expand Down
57 changes: 9 additions & 48 deletions src/canvas/Content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEmpty, npx, dpr, Range, canvasLog } from '@/util';
import { renderCell, resizeCanvas } from './util';
import { npx, dpr, canvasLog } from '@/util';
import { resizeCanvas, renderCellData } from './util';
import { ContentView, IController, EventType } from '@/types';

export class Content implements ContentView {
Expand Down Expand Up @@ -51,68 +51,29 @@ export class Content implements ContentView {
const { controller, ctx } = this;
const { width, height } = controller.getDomRect();
const headerSize = controller.getHeaderSize();
const currentSheetId = controller.getCurrentSheetId();
const { row, col } = controller.getScroll();

let x = headerSize.width;
let c = col;
let y = headerSize.height;
let r = row;

// eslint-disable-next-line no-constant-condition
while (1) {
const t = controller.getColWidth(c);
if (x + t < width) {
x += t;
c++;
} else {
break;
}
while (x + controller.getColWidth(c).len < width) {
x += controller.getColWidth(c).len;
c++;
}

// eslint-disable-next-line no-constant-condition
while (1) {
const t = controller.getRowHeight(r);
if (y + t < height) {
y += t;
r++;
} else {
break;
}
while (y + controller.getRowHeight(r).len < height) {
y += controller.getRowHeight(r).len
r++;
}
const endRow = r;
const endCol = c;
ctx.save();
y = headerSize.height;
for (let rowIndex = row; rowIndex < endRow; rowIndex++) {
x = headerSize.width;
for (let colIndex = col; colIndex < endCol; colIndex++) {
const cellInfo = controller.getCell(
new Range(rowIndex, colIndex, 1, 1, currentSheetId),
);
if (!cellInfo) {
continue;
}
if (isEmpty(cellInfo.value) && isEmpty(cellInfo.style)) {
x += controller.getColWidth(colIndex);
continue;
}
const cellSize = controller.getCellSize(rowIndex, colIndex);
if (cellSize.width <= 0 || cellSize.height <= 0) {
continue;
}
const { wrapHeight = 0 } = renderCell(ctx, {
...cellInfo,
...cellSize,
top: y,
left: x,
});
if (wrapHeight > cellSize.height) {
controller.setRowHeight(rowIndex, wrapHeight, false);
}
x += controller.getColWidth(colIndex);
renderCellData(controller, ctx, rowIndex, colIndex);
}
y += controller.getRowHeight(rowIndex);
}
ctx.restore();
}
Expand Down
Loading

0 comments on commit c49c1ba

Please sign in to comment.