lint and clean up some things

This commit is contained in:
DD Liu 2017-10-19 20:43:28 -04:00 committed by DD
parent 6732483d80
commit dbe24ed50c
2 changed files with 15 additions and 12 deletions

View file

@ -7,7 +7,7 @@ import Modes from '../modes/modes';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; 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 RectTool from '../helper/tools/rect-tool';
import RectModeComponent from '../components/rect-mode/rect-mode.jsx'; import RectModeComponent from '../components/rect-mode/rect-mode.jsx';
@ -39,7 +39,7 @@ class RectMode extends React.Component {
return nextProps.isRectModeActive !== this.props.isRectModeActive; return nextProps.isRectModeActive !== this.props.isRectModeActive;
} }
activateTool () { activateTool () {
this.props.clearSelectedItems(); clearSelection(this.props.clearSelectedItems);
this.tool = new RectTool( this.tool = new RectTool(
this.props.setSelectedItems, this.props.setSelectedItems,
this.props.clearSelectedItems, this.props.clearSelectedItems,

View file

@ -51,18 +51,15 @@ class RectTool extends paper.Tool {
this.colorState = colorState; this.colorState = colorState;
} }
handleMouseDown (event) { handleMouseDown (event) {
const clickedItem = paper.project.hitTest(event.point, this.getHitOptions()); if (this.boundingBoxTool.onMouseDown(event, false /* clone */, false /* multiselect */, this.getHitOptions())) {
if (clickedItem) {
this.isBoundingBoxMode = true; this.isBoundingBoxMode = true;
this.boundingBoxTool.onMouseDown(event, false /* clone */, false /* multiselect */, this.getHitOptions());
} else { } else {
this.isBoundingBoxMode = false; this.isBoundingBoxMode = false;
this.boundingBoxTool.removeBoundsPath();
clearSelection(this.clearSelectedItems); clearSelection(this.clearSelectedItems);
} }
} }
handleMouseDrag (event) { 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) { if (this.isBoundingBoxMode) {
this.boundingBoxTool.onMouseDrag(event); this.boundingBoxTool.onMouseDrag(event);
@ -86,7 +83,7 @@ class RectTool extends paper.Tool {
styleShape(this.rect, this.colorState); styleShape(this.rect, this.colorState);
} }
handleMouseUp (event) { 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) { if (this.isBoundingBoxMode) {
this.boundingBoxTool.onMouseUp(event); this.boundingBoxTool.onMouseUp(event);
@ -95,10 +92,16 @@ class RectTool extends paper.Tool {
} }
if (this.rect) { if (this.rect) {
this.rect.selected = true; if (this.rect.area < RectTool.TOLERANCE / paper.view.zoom) {
this.boundingBoxTool.setSelectionBounds(); // Tiny rectangle created unintentionally?
this.onUpdateSvg(); this.rect.remove();
this.rect = null; this.rect = null;
} else {
this.rect.selected = true;
this.boundingBoxTool.setSelectionBounds();
this.onUpdateSvg();
this.rect = null;
}
} }
} }
deactivateTool () { deactivateTool () {