Browse Source

Update highlighter and offset position update logic

pull/2524/head
Artur Arseniev 7 years ago
parent
commit
6e0658bf8b
  1. 12
      src/canvas/view/CanvasView.js
  2. 16
      src/commands/view/SelectComponent.js
  3. 8
      src/commands/view/ShowOffset.js

12
src/canvas/view/CanvasView.js

@ -127,12 +127,12 @@ export default Backbone.View.extend({
* @private * @private
*/ */
onFrameScroll({ body = {} } = {}) { onFrameScroll({ body = {} } = {}) {
const u = 'px'; // const u = 'px';
const bodyEl = this.frame.el.contentDocument.body; // const bodyEl = this.frame.el.contentDocument.body;
const zoom = this.getZoom(); // const zoom = this.getZoom();
this.toolsEl.style.top = '-' + bodyEl.scrollTop * zoom + u; // this.toolsEl.style.top = '-' + bodyEl.scrollTop * zoom + u;
this.toolsEl.style.left = '-' + bodyEl.scrollLeft * zoom + u; // this.toolsEl.style.left = '-' + bodyEl.scrollLeft * zoom + u;
this.em.trigger('canvasScroll'); // this.em.trigger('canvasScroll');
}, },
/** /**

16
src/commands/view/SelectComponent.js

@ -54,6 +54,7 @@ export default {
em[method]('change:componentHovered', this.onHovered, this); em[method]('change:componentHovered', this.onHovered, this);
em[method]('component:update', this.updateAttached, this); em[method]('component:update', this.updateAttached, this);
em[method]('change:canvasOffset', this.updateAttached, this); em[method]('change:canvasOffset', this.updateAttached, this);
em[method]('frame:scroll', this.onFrameScroll);
}; };
trigger(win, body); // TODO remove trigger(win, body); // TODO remove
em.get('Canvas') em.get('Canvas')
@ -138,7 +139,9 @@ export default {
this.editor.runCommand('show-offset', { this.editor.runCommand('show-offset', {
el, el,
elPos: pos, elPos: pos,
force: 1 force: 1,
top: this.frameRect(el, 1, pos),
left: this.frameRect(el, 0, pos)
}); });
}, },
@ -313,6 +316,13 @@ export default {
} }
}, },
frameRect(el, top = 1, pos) {
const side = top ? 'top' : 'left';
const { scrollTop = 0, scrollLeft = 0 } = el.ownerDocument.body || {};
return pos[side] - (top ? scrollTop : scrollLeft);
},
/** /**
* Update highlighter element * Update highlighter element
* @param {HTMLElement} el * @param {HTMLElement} el
@ -334,8 +344,8 @@ export default {
var hlEl = this.canvas.getHighlighter(); var hlEl = this.canvas.getHighlighter();
var hlStyle = hlEl.style; var hlStyle = hlEl.style;
var unit = 'px'; var unit = 'px';
hlStyle.left = pos.left + unit; hlStyle.left = this.frameRect(el, 0, pos) + unit;
hlStyle.top = pos.top + unit; hlStyle.top = this.frameRect(el, 1, pos) + unit;
hlStyle.height = pos.height + unit; hlStyle.height = pos.height + unit;
hlStyle.width = pos.width + unit; hlStyle.width = pos.width + unit;
hlStyle.display = 'block'; hlStyle.display = 'block';

8
src/commands/view/ShowOffset.js

@ -26,6 +26,14 @@ export default {
var canvas = editor.Canvas; var canvas = editor.Canvas;
var pos = opt.elPos || canvas.getElementPos(el); var pos = opt.elPos || canvas.getElementPos(el);
if (opt.top) {
pos.top = opt.top;
}
if (opt.left) {
pos.left = opt.left;
}
var style = window.getComputedStyle(el); var style = window.getComputedStyle(el);
var ppfx = this.ppfx; var ppfx = this.ppfx;
var stateVar = state + 'State'; var stateVar = state + 'State';

Loading…
Cancel
Save