From 491fdd075da8700341c4afa733b33200cb32a5a0 Mon Sep 17 00:00:00 2001 From: zhouxinyu Date: Tue, 13 Jun 2023 17:23:54 +0800 Subject: [PATCH] fix: fix the bug that will be overwritten after stage.setCursor --- .../vrender/fix-setCursor_2023-06-13-10-09.json | 10 ++++++++++ packages/vrender/src/core/stage.ts | 6 ++++++ packages/vrender/src/event/event-manager.ts | 4 ++-- packages/vrender/src/event/interface.ts | 3 +++ packages/vrender/src/graphic/richtext.ts | 5 +---- 5 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 common/changes/@visactor/vrender/fix-setCursor_2023-06-13-10-09.json diff --git a/common/changes/@visactor/vrender/fix-setCursor_2023-06-13-10-09.json b/common/changes/@visactor/vrender/fix-setCursor_2023-06-13-10-09.json new file mode 100644 index 000000000..6fe6ae667 --- /dev/null +++ b/common/changes/@visactor/vrender/fix-setCursor_2023-06-13-10-09.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vrender", + "comment": "fix the bug that will be overwritten after stage.setCursor", + "type": "patch" + } + ], + "packageName": "@visactor/vrender" +} \ No newline at end of file diff --git a/packages/vrender/src/core/stage.ts b/packages/vrender/src/core/stage.ts index 15505bc5e..6388f4e2c 100644 --- a/packages/vrender/src/core/stage.ts +++ b/packages/vrender/src/core/stage.ts @@ -67,6 +67,7 @@ export class Stage extends Group implements IStage { private _subView: boolean; // 是否是存在子视图 protected nextFrameRenderLayerSet: Set; protected willNextFrameRender: boolean; + protected _cursor: string; renderCount: number; dirtyBounds: IBounds | null; option3d?: IOption3D; @@ -691,6 +692,11 @@ export class Stage extends Group implements IStage { } setCursor(mode?: string): void { + this._cursor = mode; this.eventSystem.setCursor(mode); } + + getCursor() { + return this._cursor; + } } diff --git a/packages/vrender/src/event/event-manager.ts b/packages/vrender/src/event/event-manager.ts index 8ecb432d0..48d9c89f2 100644 --- a/packages/vrender/src/event/event-manager.ts +++ b/packages/vrender/src/event/event-manager.ts @@ -330,7 +330,7 @@ export class EventManager { if (isMouse) { this[propagationMethod](e, 'mousemove'); - this.cursor = e.target?.attribute?.cursor as Cursor; + this.cursor = (e.target?.attribute?.cursor as Cursor) || this.rootTarget.getCursor(); } trackingData.overTargets = e.composedPath(); @@ -354,7 +354,7 @@ export class EventManager { this.dispatchEvent(e, 'mouseover'); } if (e.pointerType === 'mouse') { - this.cursor = e.target?.attribute?.cursor as Cursor; + this.cursor = (e.target?.attribute?.cursor as Cursor) || this.rootTarget.getCursor(); } const enterEvent = this.clonePointerEvent(e, 'pointerenter'); diff --git a/packages/vrender/src/event/interface.ts b/packages/vrender/src/event/interface.ts index 6ccaeca1a..88cbf6325 100644 --- a/packages/vrender/src/event/interface.ts +++ b/packages/vrender/src/event/interface.ts @@ -44,6 +44,9 @@ export interface IEventTarget extends INode { attribute?: Partial; emit: (eventName: any, data: Dict) => boolean; + + getCursor: () => string; + setCursor: (c?: string) => void; } export interface IRender { diff --git a/packages/vrender/src/graphic/richtext.ts b/packages/vrender/src/graphic/richtext.ts index 8f8e56ae6..ebfed7564 100644 --- a/packages/vrender/src/graphic/richtext.ts +++ b/packages/vrender/src/graphic/richtext.ts @@ -319,10 +319,7 @@ export class RichText extends Graphic implements IRic this._currentHoverIcon?.setHoverState(false); this._currentHoverIcon = pickedIcon; this._currentHoverIcon.setHoverState(true); - if (pickedIcon.attribute.cursor) { - this.stage?.setCursor(pickedIcon.attribute.cursor); - // console.log(pickedIcon.attribute.cursor); - } + this.stage?.setCursor(pickedIcon.attribute.cursor); this.stage?.renderNextFrame(); } else if (!pickedIcon && this._currentHoverIcon) { this._currentHoverIcon.setHoverState(false);