Skip to content

Commit 79b0d95

Browse files
committed
feat: ctrl + shift + G 将文本节点转换为框的时候,自动将其内部左上角和右下角塞入质点
1 parent a3fc056 commit 79b0d95

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

app/src/core/stage/stageManager/concreteMethods/StageAutoAlignManager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class AutoAlign {
270270
// 检测树形结构
271271
if (!this.project.graphMethods.isTree(selectedRootEntity)) {
272272
// 不是树形结构,不做任何处理
273-
toast.error("选择的节点必须是树形结构的根节点");
273+
toast.error("选择的节点必须是树形结构,不能有菱形、环、等复杂结构");
274274
return;
275275
}
276276
this.project.autoLayoutFastTree.autoLayoutFastTreeMode(selectedRootEntity);

app/src/core/stage/stageManager/concreteMethods/StageSectionPackManager.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,41 @@ export class SectionPackManager {
164164
});
165165
newSection.adjustLocationAndSize();
166166

167+
// 创建左上角和右下角的质点
168+
const radius = ConnectPoint.CONNECT_POINT_SHRINK_RADIUS;
169+
const sectionRectangle = newSection.collisionBox.getRectangle();
170+
171+
// 左上角质点
172+
const topLeftLocation = sectionRectangle.location.clone();
173+
const topLeftCollisionBox = new CollisionBox([new Rectangle(topLeftLocation, Vector.same(radius * 2))]);
174+
const topLeftPoint = new ConnectPoint(this.project, {
175+
collisionBox: topLeftCollisionBox,
176+
});
177+
178+
// 右下角质点
179+
const bottomRightLocation = sectionRectangle.location
180+
.clone()
181+
.add(new Vector(sectionRectangle.size.x - radius * 2, sectionRectangle.size.y - radius * 2));
182+
const bottomRightCollisionBox = new CollisionBox([new Rectangle(bottomRightLocation, Vector.same(radius * 2))]);
183+
const bottomRightPoint = new ConnectPoint(this.project, {
184+
collisionBox: bottomRightCollisionBox,
185+
});
186+
187+
// 将质点添加到舞台
188+
this.project.stageManager.add(topLeftPoint);
189+
this.project.stageManager.add(bottomRightPoint);
190+
167191
// 将新的Section加入舞台
168192
this.project.stageManager.add(newSection);
169193
for (const fatherSection of fatherSections) {
170194
this.project.sectionInOutManager.goInSection([newSection], fatherSection);
195+
// 将质点放入Section
196+
// this.project.sectionInOutManager.goInSection([topLeftPoint, bottomRightPoint], fatherSection);
171197
}
172198

199+
// 将质点放入Section
200+
this.project.sectionInOutManager.goInSection([topLeftPoint, bottomRightPoint], newSection);
201+
173202
if (!ignoreEdges) {
174203
for (const edge of this.project.stageManager.getAssociations()) {
175204
if (edge instanceof Edge) {

app/src/core/stage/stageObject/entity/Section.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getTextSize } from "@/utils/font";
99
import { Color, ProgressNumber, Vector } from "@graphif/data-structures";
1010
import { id, passExtraAtArg1, passObject, serializable } from "@graphif/serializer";
1111
import { Line, Rectangle, Shape } from "@graphif/shapes";
12+
import { Value } from "platejs";
1213

1314
@passExtraAtArg1
1415
@passObject
@@ -84,7 +85,7 @@ export class Section extends ConnectableEntity {
8485
isHidden = false,
8586
isCollapsed = false,
8687
children = [] as Entity[],
87-
details = [],
88+
details = [] as Value,
8889
} = {},
8990
public unknown = false,
9091
) {

0 commit comments

Comments
 (0)