Skip to content

Commit

Permalink
Merge pull request #921 from adroitwhiz/mergeeraser-skip-child-paths
Browse files Browse the repository at this point in the history
Skip processing of child paths in mergeEraser
  • Loading branch information
fsih authored Apr 24, 2020
2 parents 153a239 + 1c6425f commit 7ffe87e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/helper/blob-tools/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SegmentBrushHelper from './segment-brush-helper';
import {MIXED, styleCursorPreview} from '../../helper/style-path';
import {clearSelection, getItems} from '../../helper/selection';
import {getGuideLayer} from '../../helper/layer';
import {isCompoundPathChild} from '../compound-path';

/**
* Shared code for the brush and eraser mode. Adds functions on the paper tool object
Expand Down Expand Up @@ -41,7 +42,7 @@ class Blobbiness {
this.brushSize = null;
this.fillColor = null;
}

/**
* Set configuration options for a blob
* @param {!object} options Configuration
Expand Down Expand Up @@ -92,7 +93,7 @@ class Blobbiness {
blob.cursorPreview.bringToFront();
blob.cursorPreview.position = event.point;
};

this.tool.onMouseDown = function (event) {
blob.resizeCursorIfNeeded(event.point);
if (event.event.button > 0) return; // only first mouse button
Expand Down Expand Up @@ -125,7 +126,7 @@ class Blobbiness {

this.tool.onMouseUp = function (event) {
if (event.event.button > 0 || !this.active) return; // only first mouse button

let lastPath;
if (blob.brush === Blobbiness.BROAD) {
lastPath = blob.broadBrushHelper.onBroadMouseUp(event, blob.tool, blob.options);
Expand Down Expand Up @@ -248,7 +249,11 @@ class Blobbiness {
// If there are selected items, try to erase from amongst those.
let items = getItems({
match: function (item) {
return item.selected && blob.isMergeable(lastPath, item) && blob.touches(lastPath, item);
return item.selected && blob.isMergeable(lastPath, item) &&
blob.touches(lastPath, item) &&
// Boolean operations will produce incorrect results if directly applied to compound path children,
// so exclude those. Their parents are also selected so boolean operations will apply to them.
!isCompoundPathChild(item);
},
class: paper.PathItem
});
Expand All @@ -258,12 +263,14 @@ class Blobbiness {
clearSelection(this.clearSelectedItems);
items = getItems({
match: function (item) {
return blob.isMergeable(lastPath, item) && blob.touches(lastPath, item);
return blob.isMergeable(lastPath, item) &&
blob.touches(lastPath, item) &&
!isCompoundPathChild(item);
},
class: paper.PathItem
});
}

for (let i = items.length - 1; i >= 0; i--) {
// TODO handle compound paths
if (items[i] instanceof paper.Path && (!items[i].fillColor || items[i].fillColor._alpha === 0)) {
Expand Down

0 comments on commit 7ffe87e

Please sign in to comment.