Skip to content

Commit 59deac3

Browse files
author
Yan Heng
committed
feat: 处理polylineTool
1 parent a45f42e commit 59deac3

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

packages/core/src/tools/ellipse-tool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class EllipseTool implements Tool {
5050
public onMouseUp({ app }: AppMouseEvent): void {
5151
app.setTool(selectTool);
5252
this.startPointer.setXY(0, 0);
53-
this.ellipse && app.canvas.setActiveObject(this.ellipse);
53+
if (this.ellipse) {
54+
app.canvas.setActiveObject(this.ellipse);
55+
}
5456
this.ellipse = null;
5557
app.render(true);
5658
}

packages/core/src/tools/polyline-tool.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ class PolylineTool implements Tool {
1212
private polyline: Polyline | null = null;
1313

1414
public onMouseDown({ app }: AppMouseEvent): void {
15+
console.log('mouseDown');
16+
1517
app.canvas.selection = false;
1618
this.points.push(app.pointer);
17-
this.polyline = new Polyline(this.points, {
18-
fill: 'transparent',
19-
stroke: 'black',
20-
strokeWidth: 2,
21-
});
22-
app.canvas.add(this.polyline);
19+
if (!this.polyline) {
20+
this.polyline = new Polyline(this.points, {
21+
fill: 'transparent',
22+
stroke: 'black',
23+
strokeWidth: 2,
24+
});
25+
app.canvas.add(this.polyline);
26+
} else {
27+
this.polyline.points = this.points;
28+
app.render();
29+
}
2330
}
2431

2532
public onMouseMove({ app }: AppMouseEvent): void {
@@ -34,13 +41,11 @@ class PolylineTool implements Tool {
3441
app.render(); // Call render after updating the polyline
3542
}
3643

37-
public onMouseUp({ app, event }: AppMouseEvent): void {
44+
public onMouseDoubleClick({ app }: AppMouseEvent) {
3845
app.setTool(selectTool);
46+
3947
if (this.polyline) {
40-
// Use setTimeout to delay the selection after the fabric.js selection process is done
41-
setTimeout(() => {
42-
app.canvas.setActiveObject(this.polyline!, event.e);
43-
}, 10);
48+
app.canvas.setActiveObject(this.polyline);
4449
}
4550

4651
this.points = [];

packages/core/src/tools/rect-tool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class RectTool implements Tool {
3939
public onMouseUp({ app }: AppMouseEvent): void {
4040
app.setTool(selectTool);
4141
this.startPointer.setXY(0, 0);
42-
this.rectangle && app.canvas.setActiveObject(this.rectangle);
42+
if (this.rectangle) {
43+
app.canvas.setActiveObject(this.rectangle);
44+
}
4345
this.rectangle = null;
4446
app.render(true);
4547
}

packages/core/src/tools/triangle-tool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class TriangleTool implements Tool {
3939
public onMouseUp({ app }: AppMouseEvent): void {
4040
app.setTool(selectTool);
4141
this.startPointer.setXY(0, 0);
42-
this.triangle && app.canvas.setActiveObject(this.triangle);
42+
if (this.triangle) {
43+
app.canvas.setActiveObject(this.triangle);
44+
}
4345
this.triangle = null;
4446
app.render(true);
4547
}

0 commit comments

Comments
 (0)