Skip to content

Commit ffc6742

Browse files
committed
refactor: on areaselection, intersect with actual rect elements
Previously it could select elements if the port intersects with the area selection
1 parent 79f8d5e commit ffc6742

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/js/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ export let app;
152152
"moveSelectedElements",
153153
"resizeElement",
154154
"openWorkflow",
155-
"updateDataInDataElement"
155+
"updateDataInDataElement",
156+
"selectElements"
156157
])
157158
},
158159
watch: {

src/js/plugins/AreaSelectionPlugin.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ const reCalc = (x1, x2, y1, y2) => {
1414
div.style.height = y4 - y3 + "px";
1515
};
1616

17+
const findViewsInAreaCustom = ({ x, y, width, height }) => {
18+
return app.elements.filter(el => {
19+
return !(
20+
x > el.position.x + el.size.width ||
21+
x + width < el.position.x ||
22+
y > el.position.y + el.size.height ||
23+
y + height < el.position.y
24+
);
25+
});
26+
};
27+
1728
const plugin = {
1829
install(Vue) {
1930
Vue.prototype.$areaSelection = Vue.observable({
20-
active: false,
21-
selectedElements: []
31+
active: false
2232
});
2333
let x1 = 0;
2434
let y1 = 0;
@@ -46,15 +56,15 @@ const plugin = {
4656
const pointX = (x - paperOffsetX - paperTranslateX) / currentScale;
4757
const pointY = (y - paperOffsetY - paperTranslateY) / currentScale;
4858

49-
Vue.prototype.$areaSelection.selectedElements = paper.findViewsInArea({
59+
const selectedElements = findViewsInAreaCustom({
5060
x: pointX,
5161
y: pointY,
5262
width: width / currentScale,
5363
height: height / currentScale
5464
});
5565

56-
for (const views of Vue.prototype.$areaSelection.selectedElements) {
57-
app.addElementToSelection(views);
66+
if (selectedElements) {
67+
app.selectElements({ elements: selectedElements });
5868
}
5969

6070
div.hidden = 1;

src/js/store/modules/Interface.js

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ const Interface = {
170170
unSelectAllElements({ commit }) {
171171
commit(UNSELECT_ALL_ELEMENTS);
172172
},
173+
selectElements({ commit }, payload) {
174+
commit(ADD_ELEMENTS_TO_SELECTION, payload);
175+
},
173176
selectAllElements({ commit, state }) {
174177
commit(ADD_ELEMENTS_TO_SELECTION, { elements: state.elements });
175178
},

0 commit comments

Comments
 (0)