Browse Source

Fix toolbar position outside of the canvas

pull/2062/head
Artur Arseniev 7 years ago
parent
commit
bc96577a5f
  1. 4
      src/canvas/index.js
  2. 4
      src/canvas/view/CanvasView.js
  3. 15
      src/commands/view/SelectComponent.js

4
src/canvas/index.js

@ -364,7 +364,9 @@ module.exports = () => {
targetWidth: target.offsetWidth,
targetHeight: target.offsetHeight,
canvasTop: canvasPos.top,
canvasLeft: canvasPos.left
canvasLeft: canvasPos.left,
canvasWidth: canvasPos.width,
canvasHeight: canvasPos.height
};
// In this way I can catch data and also change the position strategy

4
src/canvas/view/CanvasView.js

@ -413,7 +413,9 @@ module.exports = Backbone.View.extend({
return {
top: fo.top + bEl.scrollTop * zoom - co.top,
left: fo.left + bEl.scrollLeft * zoom - co.left
left: fo.left + bEl.scrollLeft * zoom - co.left,
width: co.width,
height: co.height
};
},

15
src/commands/view/SelectComponent.js

@ -561,14 +561,17 @@ module.exports = {
pos.top = pos.elementTop + pos.elementHeight;
}
// Check if not outside of the canvas
if (pos.left < pos.canvasLeft) {
pos.left = pos.canvasLeft;
// Check left position of the toolbar
const elRight = pos.elementLeft + pos.elementWidth;
let left = elRight - pos.targetWidth;
if (elRight > pos.canvasWidth) {
left -= elRight - pos.canvasWidth;
}
var leftPos = pos.left + pos.elementWidth - pos.targetWidth;
toolbarStyle.top = pos.top + unit;
toolbarStyle.left = (leftPos < 0 ? 0 : leftPos) + unit;
left = left < 0 ? 0 : left;
toolbarStyle.top = `${pos.top}${unit}`;
toolbarStyle.left = `${left}${unit}`;
toolbarStyle.opacity = '';
}
},

Loading…
Cancel
Save