Skip to content

Commit

Permalink
fix marker events not firing on restored markers
Browse files Browse the repository at this point in the history
fixes #183
  • Loading branch information
ailon committed Mar 4, 2024
1 parent c782fa0 commit 5d0d70c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/MarkerArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export class MarkerArea {
this.switchToSelectMode = this.switchToSelectMode.bind(this);
this.addDefs = this.addDefs.bind(this);
this.addDefsToImage = this.addDefsToImage.bind(this);
this.addMarkerEvents = this.addMarkerEvents.bind(this);
}

private open(): void {
Expand Down Expand Up @@ -1445,6 +1446,7 @@ export class MarkerArea {
if (markerType !== undefined) {
const marker = this.addNewMarker(markerType);
marker.restoreState(markerState);
this.addMarkerEvents(marker);
this.markers.push(marker);
}
});
Expand Down Expand Up @@ -1499,10 +1501,7 @@ export class MarkerArea {
this.setCurrentMarker();
this.addUndoStep();
this._currentMarker = this.addNewMarker(mType);
this._currentMarker.onMarkerCreated = this.markerCreated;
this._currentMarker.onColorChanged = this.colorChanged;
this._currentMarker.onFillColorChanged = this.fillColorChanged;
this._currentMarker.onStateChanged = this.markerStateChanged;
this.addMarkerEvents(this._currentMarker);
this.markerImage.style.cursor = 'crosshair';
this.toolbar.setActiveMarkerButton(mType.typeName);
this.toolbox.setPanelButtons(this._currentMarker.toolboxPanels);
Expand All @@ -1512,6 +1511,13 @@ export class MarkerArea {
}
}

private addMarkerEvents(marker: MarkerBase) {
marker.onMarkerCreated = this.markerCreated;
marker.onColorChanged = this.colorChanged;
marker.onFillColorChanged = this.fillColorChanged;
marker.onStateChanged = this.markerStateChanged;
}

private markerCreated(marker: MarkerBase) {
this.mode = 'select';
this.markerImage.style.cursor = 'default';
Expand Down
2 changes: 1 addition & 1 deletion test/manual/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Experiments {
// console.log(`redo possible?: ${event.markerArea.isRedoPossible}`);
});
this.markerArea1.addEventListener('markerchange', (event) => {
// console.log(`marker state change: ${JSON.stringify(event.marker?.getState())}`);
console.log(`marker state change: ${JSON.stringify(event.marker?.getState())}`);
});

// this.markerArea1.addEventListener('markerselect', event => {
Expand Down

0 comments on commit 5d0d70c

Please sign in to comment.