Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid creating 0-size line and shape #892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/image-editor/src/js/component/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ class Line extends Component {
_onFabricMouseUp() {
const canvas = this.getCanvas();

this.fire(eventNames.OBJECT_ADDED, this._createLineEventObjectProperties());
const line = this._createLineEventObjectProperties();
if (line.width <= 0 && line.height <= 0) {
canvas.remove(this._line);
} else {
this.fire(eventNames.OBJECT_ADDED, line);
}

this._line = null;

Expand Down
39 changes: 23 additions & 16 deletions apps/image-editor/src/js/component/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const SHAPE_INIT_OPTIONS = extend(
SHAPE_DEFAULT_OPTIONS
);
const DEFAULT_TYPE = 'rect';
const DEFAULT_WIDTH = 20;
const DEFAULT_HEIGHT = 20;
// const DEFAULT_WIDTH = 20;
// const DEFAULT_HEIGHT = 20;

/**
* Make fill option
Expand Down Expand Up @@ -480,22 +480,29 @@ export default class Shape extends Component {
*/
_onFabricMouseUp() {
const canvas = this.getCanvas();
const startPointX = this._startPoint.x;
const startPointY = this._startPoint.y;
// const startPointX = this._startPoint.x;
// const startPointY = this._startPoint.y;
const shape = this._shapeObj;

if (!shape) {
this.add(this._type, {
left: startPointX,
top: startPointY,
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT,
}).then((objectProps) => {
this.fire(eventNames.ADD_OBJECT, objectProps);
});
} else if (shape) {
resizeHelper.adjustOriginToCenter(shape);
this.fire(eventNames.OBJECT_ADDED, this.graphics.createObjectProperties(shape));
/*
if (!shape) {
this.add(this._type, {
left: startPointX,
top: startPointY,
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT,
}).then((objectProps) => {
this.fire(eventNames.ADD_OBJECT, objectProps);
});
} else
*/
if (shape) {
if (shape.width > 0 && shape.height > 0) {
resizeHelper.adjustOriginToCenter(shape);
this.fire(eventNames.OBJECT_ADDED, this.graphics.createObjectProperties(shape));
} else {
canvas.remove(shape);
}
}

canvas.off({
Expand Down