From 7b237751db0af40a1fbd72bf338c6b4aabe7a428 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 30 Sep 2019 08:52:19 +0200 Subject: [PATCH] Move scrolling check from FrameView to CanvasView --- src/canvas/view/CanvasView.js | 16 ++++++++++++++-- src/canvas/view/FrameView.js | 11 ----------- src/commands/view/SelectComponent.js | 3 +++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/canvas/view/CanvasView.js b/src/canvas/view/CanvasView.js index b8af53a44..2cea410e3 100644 --- a/src/canvas/view/CanvasView.js +++ b/src/canvas/view/CanvasView.js @@ -36,8 +36,10 @@ export default Backbone.View.extend({ this.pfx = this.config.stylePrefix || ''; this.ppfx = this.config.pStylePrefix || ''; this.className = this.config.stylePrefix + 'canvas'; - this.listenTo(this.em, 'change:canvasOffset', this.clearOff); - this.listenTo(this.em, 'frame:scroll', this.onFrameScroll); + const { em } = this; + this.listenTo(em, 'change:canvasOffset', this.clearOff); + this.listenTo(em, 'frame:scroll', this.onFrameScroll); + this.listenTo(em, 'component:selected', this.checkSelected); this.listenTo(model, 'change:zoom change:x change:y', this.updateFrames); this.toggleListeners(1); this.frame = new FrameView({ @@ -46,6 +48,16 @@ export default Backbone.View.extend({ }); }, + checkSelected(component, opts = {}) { + const { scroll } = opts; + const currFrame = this.em.get('currentFrame'); + + scroll && + component.views.forEach(view => { + view._getFrame() !== currFrame && view.scrollIntoView(scroll); + }); + }, + remove() { Backbone.View.prototype.remove.apply(this, arguments); this.toggleListeners(); diff --git a/src/canvas/view/FrameView.js b/src/canvas/view/FrameView.js index 7dada1b66..5931a3572 100644 --- a/src/canvas/view/FrameView.js +++ b/src/canvas/view/FrameView.js @@ -34,21 +34,10 @@ export default Backbone.View.extend({ this.listenTo(model, 'change:x change:y', this.updatePos); this.listenTo(model, 'change:width change:height', this.updateDim); this.listenTo(this.em, 'change:device', this.updateDim); - this.listenTo(this.em, 'component:selected', this.checkSelected); this.updatePos(); model.view = this; }, - checkSelected(component, opts = {}) { - console.log('checkSelected from FrameView', this); - const view = component && component.getView(this.model); - - if (view) { - // avoid scroll if the frame is the current one - opts.scroll && view.scrollIntoView(opts.scroll); - } - }, - updatePos(md) { const { model, el } = this; const { x, y } = model.attributes; diff --git a/src/commands/view/SelectComponent.js b/src/commands/view/SelectComponent.js index aab4516a1..0043f01d9 100644 --- a/src/commands/view/SelectComponent.js +++ b/src/commands/view/SelectComponent.js @@ -79,6 +79,8 @@ export default { onHover(e) { e.stopPropagation(); const trg = e.target; + const view = getViewEl(trg); + const frameView = view && view._getFrame(); const $el = $(trg); let model = $el.data('model'); @@ -100,6 +102,7 @@ export default { this.currentDoc = trg.ownerDocument; this.em.setHovered(model); + frameView && this.em.set('currentFrame', frameView); }, onHovered(em, component) {