From 57d31de8547ec2e3b1f716d2dc93faa6862baa50 Mon Sep 17 00:00:00 2001 From: L-Sun Date: Fri, 23 May 2025 03:08:40 +0000 Subject: [PATCH] fix(editor): support single-tap brush (#12461) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close [BS-3519](https://linear.app/affine-design/issue/BS-3519/白板支持手写笔点写) ## Summary by CodeRabbit - **New Features** - Introduced the ability to add new brush elements by clicking, capturing precise pointer location and pressure data when supported. - **Bug Fixes** - Improved stability when updating brush elements during dragging. --- blocksuite/affine/gfx/brush/src/brush-tool.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/blocksuite/affine/gfx/brush/src/brush-tool.ts b/blocksuite/affine/gfx/brush/src/brush-tool.ts index 3622b779ec..309c86f00f 100644 --- a/blocksuite/affine/gfx/brush/src/brush-tool.ts +++ b/blocksuite/affine/gfx/brush/src/brush-tool.ts @@ -1,4 +1,7 @@ -import { CanvasElementType } from '@blocksuite/affine-block-surface'; +import { + CanvasElementType, + EdgelessCRUDIdentifier, +} from '@blocksuite/affine-block-surface'; import type { BrushElementModel } from '@blocksuite/affine-model'; import { TelemetryProvider } from '@blocksuite/affine-shared/services'; import type { IVec } from '@blocksuite/global/gfx'; @@ -118,7 +121,7 @@ export class BrushTool extends BaseTool { this._lastPoint = [pointX, pointY]; this._draggingPathPoints = points; - this.gfx.updateElement(this._draggingElement!, { + this.gfx.updateElement(this._draggingElement, { points: this._tryGetPressurePoints(e), }); @@ -167,6 +170,24 @@ export class BrushTool extends BaseTool { this._lastPopLength = 0; } + override click(e: PointerEventState) { + this.doc.captureSync(); + + const [modelX, modelY] = this.gfx.viewport.toModelCoord( + e.point.x, + e.point.y + ); + + const points = this._pressureSupportedPointerIds.has(e.raw.pointerId) + ? [[modelX, modelY, e.pressure]] + : [[modelX, modelY]]; + + const crud = this.std.get(EdgelessCRUDIdentifier); + crud.addElement(CanvasElementType.BRUSH, { + points, + }); + } + override activate() { this.std.getOptional(TelemetryProvider)?.track('EdgelessToolPicked', { page: 'whiteboard editor',