Browse Source

Move scrolling check from FrameView to CanvasView

pull/2524/head
Artur Arseniev 7 years ago
parent
commit
7b237751db
  1. 16
      src/canvas/view/CanvasView.js
  2. 11
      src/canvas/view/FrameView.js
  3. 3
      src/commands/view/SelectComponent.js

16
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();

11
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;

3
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) {

Loading…
Cancel
Save