Skip to content

Commit 44e68e6

Browse files
committed
✨ 增加新快捷键:ctrl+shift+g,将section框转变为文本节点,并将内部内容掉出身体。
1 parent e40f7d6 commit 44e68e6

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export namespace StageSectionPackManager {
6868
}
6969
}
7070
}
71+
7172
/**
7273
* 将所有选中的节点当场转换成Section
7374
*/
@@ -161,6 +162,55 @@ export namespace StageSectionPackManager {
161162
return newSection;
162163
}
163164

165+
/**
166+
* 拆包操作
167+
*/
168+
export function unpackSelectedSections() {
169+
const selectedSections = StageManager.getSelectedEntities();
170+
unpackSections(selectedSections);
171+
StageHistoryManager.recordStep();
172+
}
173+
174+
/**
175+
* 打包的反操作:拆包
176+
* @param entities 要拆包的实体
177+
* 如果选择了section内部一层的实体,则父section脱离剥皮,变成一个textNode
178+
* 如果选择的是一个section,则其本身脱离剥皮,变成一个textNode,内部内容掉落出来。
179+
*/
180+
function unpackSections(entities: Entity[]) {
181+
if (entities.length === 0) return;
182+
// 目前先仅支持选中section后再进行拆包操作
183+
const sections = entities.filter((entity) => entity instanceof Section);
184+
if (sections.length === 0) {
185+
Dialog.show({
186+
title: "请选择一个section",
187+
content: "请选择一个section",
188+
});
189+
return;
190+
}
191+
for (const section of sections) {
192+
const currentSectionFathers = SectionMethods.getFatherSections(section);
193+
// 生成一个textnode
194+
const sectionLocation = section.collisionBox.getRectangle().location;
195+
const textNode = new TextNode({
196+
uuid: v4(),
197+
text: section.text,
198+
details: section.details,
199+
location: [sectionLocation.x, sectionLocation.y],
200+
size: [100, 100],
201+
color: section.color.toArray(),
202+
});
203+
// 将textNode添加到舞台
204+
StageManager.addTextNode(textNode);
205+
// 将新的textnode添加到父section中
206+
StageSectionInOutManager.goInSections([textNode], currentSectionFathers);
207+
// 将section的子节点添加到父section中
208+
StageSectionInOutManager.goInSections(section.children, currentSectionFathers);
209+
// 将section从舞台中删除
210+
StageManager.deleteEntities([section]);
211+
}
212+
}
213+
164214
/** 将多个实体打包成一个section,并添加到舞台中 */
165215
export async function packEntityToSection(addEntities: Entity[]) {
166216
if (addEntities.length === 0) {

app/src/locales/zh_CN.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,11 @@ keyBinds:
613613
title: 将选中的实体打包到Section框中
614614
description: |
615615
按下后,选中的实体会自动包裹到新Section框中
616+
unpackEntityFromSection:
617+
title: Section框拆包,转换为文本节点
618+
description: |
619+
按下后,选中的Section框中的实体会被拆包,自身转换成一个文本节点
620+
内部的实体将会掉落在外面
616621
textNodeToSection:
617622
title: 将选中的文本节点转换成Section框
618623
description: |

app/src/main.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ async function registerKeyBinds() {
480480
).down(() => {
481481
StageSectionPackManager.textNodeToSection();
482482
});
483+
(
484+
await KeyBinds.create("unpackEntityFromSection", "g", {
485+
control: isMac ? false : true,
486+
meta: isMac,
487+
alt: false,
488+
shift: true,
489+
})
490+
).down(() => {
491+
StageSectionPackManager.unpackSelectedSections();
492+
});
483493
(
484494
await KeyBinds.create("checkoutProtectPrivacy", "2", {
485495
control: isMac ? false : true,

0 commit comments

Comments
 (0)