fix(stage): 修复鼠标移出画布后,highlight没有清除

This commit is contained in:
roymondchen 2022-04-13 15:26:10 +08:00 committed by jia000
parent f7ba716fe9
commit 9cb821c491
2 changed files with 9 additions and 0 deletions

View File

@ -56,6 +56,7 @@ export default class StageHighlight extends EventEmitter {
*/ */
public clearHighlight(): void { public clearHighlight(): void {
if (!this.moveable) return; if (!this.moveable) return;
this.target = undefined;
this.moveable.target = null; this.moveable.target = null;
this.moveable.updateTarget(); this.moveable.updateTarget();
} }

View File

@ -106,6 +106,7 @@ export default class StageMask extends Rule {
this.wrapper.appendChild(this.content); this.wrapper.appendChild(this.content);
this.content.addEventListener('wheel', this.mouseWheelHandler); this.content.addEventListener('wheel', this.mouseWheelHandler);
this.content.addEventListener('mousemove', this.highlightHandler); this.content.addEventListener('mousemove', this.highlightHandler);
this.content.addEventListener('mouseleave', this.mouseLeaveHandler);
} }
public setMode(mode: Mode) { public setMode(mode: Mode) {
@ -141,6 +142,7 @@ export default class StageMask extends Rule {
this.fixScrollValue(); this.fixScrollValue();
this.scroll(); this.scroll();
this.core.dr.updateMoveable();
}); });
this.pageResizeObserver.observe(page); this.pageResizeObserver.observe(page);
@ -180,6 +182,8 @@ export default class StageMask extends Rule {
this.pageScrollParent = null; this.pageScrollParent = null;
this.pageResizeObserver?.disconnect(); this.pageResizeObserver?.disconnect();
this.wrapperResizeObserver?.disconnect(); this.wrapperResizeObserver?.disconnect();
this.content.removeEventListener('mouseleave', this.mouseLeaveHandler);
super.destroy(); super.destroy();
} }
@ -301,4 +305,8 @@ export default class StageMask extends Rule {
this.emit('scroll', event); this.emit('scroll', event);
}; };
private mouseLeaveHandler = () => {
setTimeout(() => this.emit('clearHighlight'), throttleTime);
};
} }