Skip to content

Commit

Permalink
fix(stage): 隐藏标尺后再显示标尺,拖出来的线没有吸附作用
Browse files Browse the repository at this point in the history
fix #548
  • Loading branch information
roymondchen committed Nov 6, 2023
1 parent 168ec28 commit 7a228b1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/stage/src/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export default class Rule extends EventEmitter {
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
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.vGuides.resize();
this.hGuides.resize();
Expand Down Expand Up @@ -129,8 +126,8 @@ export default class Rule extends EventEmitter {
height: type === GuidesType.HORIZONTAL ? '30px' : '100%',
});

private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides =>
new Guides(this.container, {
private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides => {
const guides = new Guides(this.container, {
type,
defaultGuides,
displayDragPos: true,
Expand All @@ -141,6 +138,18 @@ export default class Rule extends EventEmitter {
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']) => {
this.horizontalGuidelines = e.guides;
this.emit('change-guides', {
Expand Down

0 comments on commit 7a228b1

Please sign in to comment.