mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 13:17:10 +08:00
fix(editor): suface component can be null (#12270)
Closes: BS-3149 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved internal handling of surface components across various tools, resulting in safer and more consistent access patterns. - Enhanced code maintainability and reliability without altering any visible features or user workflows. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -34,6 +34,10 @@ export class EraserTool extends BaseTool {
|
||||
|
||||
private readonly _eraseTargets = new Set<GfxModel>();
|
||||
|
||||
private get _surfaceComponent() {
|
||||
return this.gfx.surfaceComponent as SurfaceBlockComponent | null;
|
||||
}
|
||||
|
||||
private readonly _loop = () => {
|
||||
const now = Date.now();
|
||||
const elapsed = now - this._timestamp;
|
||||
@@ -59,7 +63,7 @@ export class EraserTool extends BaseTool {
|
||||
})
|
||||
);
|
||||
this._overlay.d = d;
|
||||
(this.gfx.surfaceComponent as SurfaceBlockComponent)?.refresh();
|
||||
this._surfaceComponent?.refresh();
|
||||
}
|
||||
this._timer = requestAnimationFrame(this._loop);
|
||||
};
|
||||
@@ -81,9 +85,7 @@ export class EraserTool extends BaseTool {
|
||||
return;
|
||||
}
|
||||
|
||||
(
|
||||
this.gfx.surfaceComponent as SurfaceBlockComponent
|
||||
)?.renderer.removeOverlay(this._overlay);
|
||||
this._surfaceComponent?.renderer.removeOverlay(this._overlay);
|
||||
this._erasable.clear();
|
||||
this._eraseTargets.clear();
|
||||
}
|
||||
@@ -150,8 +152,7 @@ export class EraserTool extends BaseTool {
|
||||
...this.gfx.layer.blocks,
|
||||
]);
|
||||
this._loop();
|
||||
(this.gfx.surfaceComponent as SurfaceBlockComponent)?.renderer.addOverlay(
|
||||
this._overlay
|
||||
);
|
||||
|
||||
this._surfaceComponent?.renderer.addOverlay(this._overlay);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user