Skip to content

Commit 370cb83

Browse files
committed
🐛 修复mac无法编辑section文字的功能
1 parent 39e209b commit 370cb83

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

app/src/core/render/canvas2d/entityRenderer/section/SectionRenderer.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ export namespace SectionRenderer {
3939
2 * Camera.currentScale,
4040
Renderer.NODE_ROUNDED_RADIUS * 1.5 * Camera.currentScale,
4141
);
42-
43-
TextRenderer.renderText(
44-
section.text,
45-
Renderer.transformWorld2View(section.rectangle.location.add(Vector.same(Renderer.NODE_PADDING))),
46-
Renderer.FONT_SIZE * Camera.currentScale,
47-
section.color.a === 1 ? colorInvert(section.color) : colorInvert(StageStyleManager.currentStyle.BackgroundColor),
48-
);
42+
if (!section.isEditingTitle) {
43+
TextRenderer.renderText(
44+
section.text,
45+
Renderer.transformWorld2View(section.rectangle.location.add(Vector.same(Renderer.NODE_PADDING))),
46+
Renderer.FONT_SIZE * Camera.currentScale,
47+
section.color.a === 1
48+
? colorInvert(section.color)
49+
: colorInvert(StageStyleManager.currentStyle.BackgroundColor),
50+
);
51+
}
4952
}
5053

5154
// 非折叠状态
@@ -61,7 +64,7 @@ export namespace SectionRenderer {
6164
Camera.currentScale > 0.2 ? 2 * Camera.currentScale : 2,
6265
Renderer.NODE_ROUNDED_RADIUS * Camera.currentScale,
6366
);
64-
if (Camera.currentScale > 0.2) {
67+
if (Camera.currentScale > 0.2 && !section.isEditingTitle) {
6568
// 正常显示标题
6669
TextRenderer.renderText(
6770
section.text,

app/src/core/service/controlService/controller/concrete/ControllerSectionEdit.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Stage } from "../../../../stage/Stage";
44
import { StageManager } from "../../../../stage/stageManager/StageManager";
55

66
import { ControllerClass } from "../ControllerClass";
7+
import { editSectionTitle } from "./utilsControl";
78

89
/**
910
* 包含编辑节点文字,编辑详细信息等功能的控制器
@@ -22,12 +23,7 @@ ControllerSectionEdit.mouseDoubleClick = (event: MouseEvent) => {
2223
}
2324

2425
// 编辑文字
25-
const user_input = prompt("请输入文字", firstHoverSection.text);
26-
if (user_input) {
27-
for (const section of Stage.mouseInteractionCore.hoverSections) {
28-
section.rename(user_input);
29-
}
30-
}
26+
editSectionTitle(firstHoverSection);
3127
return;
3228
};
3329

app/src/core/service/controlService/controller/concrete/utilsControl.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { StageManager } from "../../../../stage/stageManager/StageManager";
1212
import { Entity } from "../../../../stage/stageObject/abstract/StageEntity";
1313
import { LineEdge } from "../../../../stage/stageObject/association/LineEdge";
1414
import { PortalNode } from "../../../../stage/stageObject/entity/PortalNode";
15+
import { Section } from "../../../../stage/stageObject/entity/Section";
1516
import { TextNode } from "../../../../stage/stageObject/entity/TextNode";
1617
import { UrlNode } from "../../../../stage/stageObject/entity/UrlNode";
1718
import { EntityCreateFlashEffect } from "../../../feedbackService/effectEngine/concrete/EntityCreateFlashEffect";
@@ -110,6 +111,32 @@ export function editUrlNodeTitle(clickedUrlNode: UrlNode) {
110111
});
111112
}
112113

114+
export function editSectionTitle(section: Section) {
115+
Controller.isCameraLocked = true;
116+
// 编辑节点
117+
section.isEditingTitle = true;
118+
InputElement.input(
119+
Renderer.transformWorld2View(section.rectangle.location).add(
120+
Vector.same(Renderer.NODE_PADDING).multiply(Camera.currentScale),
121+
),
122+
section.text,
123+
(text) => {
124+
section.rename(text);
125+
},
126+
{
127+
fontSize: Renderer.FONT_SIZE * Camera.currentScale + "px",
128+
backgroundColor: "transparent",
129+
color: StageStyleManager.currentStyle.StageObjectBorderColor.toString(),
130+
outline: "none",
131+
marginTop: -8 * Camera.currentScale + "px",
132+
},
133+
).then(() => {
134+
section.isEditingTitle = false;
135+
Controller.isCameraLocked = false;
136+
StageHistoryManager.recordStep();
137+
});
138+
}
139+
113140
export function editPortalNodeTitle(clickedPortalNode: PortalNode) {
114141
Controller.isCameraLocked = true;
115142
// 编辑节点

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class Section extends ConnectableEntity {
2222
*/
2323
_isSelected: boolean = false;
2424
public uuid: string;
25-
25+
public isEditingTitle: boolean = false;
2626
private _collisionBoxWhenCollapsed: CollisionBox;
2727
private _collisionBoxNormal: CollisionBox;
2828

0 commit comments

Comments
 (0)