From dbe24ed50c0a1d1fec8f1492788182c306992d40 Mon Sep 17 00:00:00 2001 From: DD Liu Date: Thu, 19 Oct 2017 20:43:28 -0400 Subject: [PATCH] lint and clean up some things --- src/containers/rect-mode.jsx | 4 ++-- src/helper/tools/rect-tool.js | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/containers/rect-mode.jsx b/src/containers/rect-mode.jsx index 5c1fe557..59a2faee 100644 --- a/src/containers/rect-mode.jsx +++ b/src/containers/rect-mode.jsx @@ -7,7 +7,7 @@ import Modes from '../modes/modes'; import {changeMode} from '../reducers/modes'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; -import {getSelectedLeafItems} from '../helper/selection'; +import {clearSelection, getSelectedLeafItems} from '../helper/selection'; import RectTool from '../helper/tools/rect-tool'; import RectModeComponent from '../components/rect-mode/rect-mode.jsx'; @@ -39,7 +39,7 @@ class RectMode extends React.Component { return nextProps.isRectModeActive !== this.props.isRectModeActive; } activateTool () { - this.props.clearSelectedItems(); + clearSelection(this.props.clearSelectedItems); this.tool = new RectTool( this.props.setSelectedItems, this.props.clearSelectedItems, diff --git a/src/helper/tools/rect-tool.js b/src/helper/tools/rect-tool.js index 8ec0dfec..db0368c9 100644 --- a/src/helper/tools/rect-tool.js +++ b/src/helper/tools/rect-tool.js @@ -51,18 +51,15 @@ class RectTool extends paper.Tool { this.colorState = colorState; } handleMouseDown (event) { - const clickedItem = paper.project.hitTest(event.point, this.getHitOptions()); - if (clickedItem) { + if (this.boundingBoxTool.onMouseDown(event, false /* clone */, false /* multiselect */, this.getHitOptions())) { this.isBoundingBoxMode = true; - this.boundingBoxTool.onMouseDown(event, false /* clone */, false /* multiselect */, this.getHitOptions()); } else { this.isBoundingBoxMode = false; - this.boundingBoxTool.removeBoundsPath(); clearSelection(this.clearSelectedItems); } } handleMouseDrag (event) { - if (event.event.button > 0) return; // only first mouse button + if (event.event.button > 0) return; // only first mouse button if (this.isBoundingBoxMode) { this.boundingBoxTool.onMouseDrag(event); @@ -86,7 +83,7 @@ class RectTool extends paper.Tool { styleShape(this.rect, this.colorState); } handleMouseUp (event) { - if (event.event.button > 0) return; // only first mouse button + if (event.event.button > 0) return; // only first mouse button if (this.isBoundingBoxMode) { this.boundingBoxTool.onMouseUp(event); @@ -95,10 +92,16 @@ class RectTool extends paper.Tool { } if (this.rect) { - this.rect.selected = true; - this.boundingBoxTool.setSelectionBounds(); - this.onUpdateSvg(); - this.rect = null; + if (this.rect.area < RectTool.TOLERANCE / paper.view.zoom) { + // Tiny rectangle created unintentionally? + this.rect.remove(); + this.rect = null; + } else { + this.rect.selected = true; + this.boundingBoxTool.setSelectionBounds(); + this.onUpdateSvg(); + this.rect = null; + } } } deactivateTool () {