Skip to content

Commit

Permalink
chore: discard invisible cell view data
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Jan 4, 2025
1 parent d282817 commit 79fc514
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/components/canvas/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ const Internal: FC<CanvasProps> = observer((props: CanvasProps) => {
let lastScrollTime = 0
const onMouseWheel = (e: WheelEvent) => {
// only support y scrollbar currently
if (store.anchorY + e.deltaY < 0) {
store.setAnchor(store.anchorX, 0)
return
let delta = e.deltaY
if (store.anchorY + delta < 0) {
delta = -store.anchorY
}

const now = Date.now()
if (now - lastScrollTime < 200) return
if (now - lastScrollTime < 150) return

lastScrollTime = now
store.setAnchor(store.anchorX, store.anchorY + e.deltaY)
store.setAnchor(store.anchorX, store.anchorY + delta)
store.render.render()
store.scrollbar.update('y')
store.scroll()
Expand Down
8 changes: 7 additions & 1 deletion src/components/canvas/store/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ export class Render {
this.store.currSheetIdx,
this.store.anchorX - BUFFER_SIZE,
this.store.anchorY - BUFFER_SIZE,
rect.height + BUFFER_SIZE * 2,
rect.height + BUFFER_SIZE,
rect.width + BUFFER_SIZE
)
resp.then((r) => {
if (isErrorMessage(r)) return
const req = r.request
// Discard responses that are invisible now
if (Math.abs(req.startX - this.store.anchorX) > req.width) return
if (Math.abs(req.startY - this.store.anchorY) > req.height) {
return
}
const data = r.data
this._painterService.setupCanvas(this.canvas)
this._painterService.clear()
Expand Down
19 changes: 18 additions & 1 deletion src/core/data2/view_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ export class ViewManager {
return a.fromRow < b.fromRow || a.fromCol < b.fromCol ? -1 : 1
})

return {type, data: new CellView(this.dataChunks)}
return {
type,
data: new CellView(this.dataChunks),
request: {
startX,
startY,
height,
width,
},
}
}

/**
Expand All @@ -89,9 +98,17 @@ export enum CellViewRespType {
New,
}

export interface CellViewRequest {
readonly startX: number
readonly startY: number
readonly height: number
readonly width: number
}

export interface CellViewResponse {
readonly type: CellViewRespType
readonly data: CellView
readonly request: CellViewRequest
}

export function parseDisplayWindow(
Expand Down

0 comments on commit 79fc514

Please sign in to comment.