From 70a65cc0a39763cc169832d371c5b0e11a1e7174 Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 5 Aug 2016 22:48:40 +0200 Subject: [PATCH] client/notes: fix saving post breaking selection The problem was with dangling references - the saved post has been replacing the note collection with entirely new class instances, whereas the notes control clung onto old references. Now the control detects such reloads and acts accordingly. --- client/js/controls/post_notes_overlay_control.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/client/js/controls/post_notes_overlay_control.js b/client/js/controls/post_notes_overlay_control.js index d29da2c7..eb52f6b2 100644 --- a/client/js/controls/post_notes_overlay_control.js +++ b/client/js/controls/post_notes_overlay_control.js @@ -552,6 +552,7 @@ class PostNotesOverlayControl extends events.EventTarget { this._createPolygonNode(note); } this._hostNode.appendChild(this._svgNode); + this._post.addEventListener('change', e => this._evtPostChange(e)); this._post.notes.addEventListener('remove', e => { this._deletePolygonNode(e.detail.note); }); @@ -597,6 +598,16 @@ class PostNotesOverlayControl extends events.EventTarget { return this._hostNode.getBoundingClientRect(); } + _evtPostChange(e) { + while (this._svgNode.childNodes.length) { + this._svgNode.removeChild(this._svgNode.firstChild); + } + this._post = e.detail.post; + for (let note of this._post.notes) { + this._createPolygonNode(note); + } + } + _evtCanvasKeyDown(e) { this._state.evtCanvasKeyDown(e); }