fix(stage): 隐藏标尺后再显示标尺,拖出来的线没有吸附作用

fix #548
This commit is contained in:
roymondchen 2023-11-06 14:16:16 +08:00
parent 168ec281aa
commit 7a228b13e6

View File

@ -21,9 +21,6 @@ export default class Rule extends EventEmitter {
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines); this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines); this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
this.hGuides.on('changeGuides', this.hGuidesChangeGuidesHandler);
this.vGuides.on('changeGuides', this.vGuidesChangeGuidesHandler);
this.containerResizeObserver = new ResizeObserver(() => { this.containerResizeObserver = new ResizeObserver(() => {
this.vGuides.resize(); this.vGuides.resize();
this.hGuides.resize(); this.hGuides.resize();
@ -129,8 +126,8 @@ export default class Rule extends EventEmitter {
height: type === GuidesType.HORIZONTAL ? '30px' : '100%', height: type === GuidesType.HORIZONTAL ? '30px' : '100%',
}); });
private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides => private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides => {
new Guides(this.container, { const guides = new Guides(this.container, {
type, type,
defaultGuides, defaultGuides,
displayDragPos: true, displayDragPos: true,
@ -141,6 +138,18 @@ export default class Rule extends EventEmitter {
showGuides: this.isShowGuides, showGuides: this.isShowGuides,
}); });
const changEventHandler = {
[GuidesType.HORIZONTAL]: this.hGuidesChangeGuidesHandler,
[GuidesType.VERTICAL]: this.vGuidesChangeGuidesHandler,
}[type];
if (changEventHandler) {
guides.on('changeGuides', changEventHandler);
}
return guides;
};
private hGuidesChangeGuidesHandler = (e: GuidesEvents['changeGuides']) => { private hGuidesChangeGuidesHandler = (e: GuidesEvents['changeGuides']) => {
this.horizontalGuidelines = e.guides; this.horizontalGuidelines = e.guides;
this.emit('change-guides', { this.emit('change-guides', {