Skip to content

Commit 25c89e4

Browse files
authored
MAJOR improvements to merge tool
1 parent 896d6dc commit 25c89e4

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

src/containers/mode-tools.jsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -343,58 +343,57 @@ class ModeTools extends React.Component {
343343
});
344344
}
345345

346-
async handleMergeShape (specificOperation) {
346+
async handleMergeShape (event, operation = "unite") {
347347
const selectedItems = getSelectedRootItems();
348348
if (selectedItems.length < 2) {
349349
// If nothing or not enough items are selected,
350350
// we probably shouldnt select and merge everything
351351
return;
352352
}
353353

354-
// Convert text items to paths
354+
// Convert possible text items to paths
355355
for (let i = 0; i < selectedItems.length; i++) {
356356
if (selectedItems[i].className === "PointText") {
357357
const path = await this.convertText2Path(selectedItems[i]);
358358
if (path) selectedItems[i] = path;
359359
}
360360
}
361361

362-
const topItem = selectedItems[0];
362+
let topItem = selectedItems[0];
363363
if (topItem.className !== "PointText" && !topItem.unite) {
364364
// we cant unite this item, cancel
365365
return;
366366
}
367367

368-
console.log(specificOperation);
369-
if (typeof specificOperation !== "string") specificOperation = "unite";
368+
if (typeof operation !== "string") operation = "unite";
370369

371-
if (window.test) {
372-
window.test(selectedItems, topItem, specificOperation, this, setItemSelection);
373-
return
374-
}
375370
// unite the shapes together, creating a clone on top of the original
376-
const results = [];
371+
let oldTopItem;
377372
for (let i = 1; i < selectedItems.length; i++) {
378-
const result = topItem[specificOperation](selectedItems[i]);
379-
results.push(result);
373+
topItem = topItem[operation](selectedItems[i]);
374+
if (oldTopItem) oldTopItem.remove();
375+
oldTopItem = topItem;
380376
}
381377

382-
if (results.length <= 1) {
383-
setItemSelection(results[0], true);
384-
this.props.onUpdateImage();
385-
} else {
386-
groupItems(results, this.props.clearSelectedItems, this.props.setSelectedItems, this.props.onUpdateImage);
378+
// if shift is pressed, remove the old items
379+
if (event.shiftKey) {
380+
for (const item of selectedItems) {
381+
item.remove();
382+
}
387383
}
384+
385+
setItemSelection(results[0], true);
386+
this.props.onUpdateImage();
388387
}
389388

390-
handleMaskShape () {
391-
this.handleMergeShape("intersect");
389+
handleMaskShape (event) {
390+
this.handleMergeShape(event, "intersect");
392391
}
393-
handleSubtractShape () {
394-
this.handleMergeShape("subtract");
392+
handleSubtractShape (event) {
393+
this.handleMergeShape(event, "subtract");
395394
}
396-
handleExcludeShape () {
397-
this.handleMergeShape("exclude");
395+
handleExcludeShape (event) {
396+
this.handleMergeShape(event, "exclude");
398397
}
399398

400399
_handleFlip (horizontalScale, verticalScale, selectedItems) {

0 commit comments

Comments
 (0)