Skip to content

Commit 960a476

Browse files
committed
🥚 增加秘籍键“kei”,分割节点
1 parent ff4f411 commit 960a476

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

app/src/core/service/controlService/secretEngine/secretEngine.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,40 @@ export class SecretEngine {
403403
}
404404
},
405405
},
406+
"k e i": {
407+
name: "将选中的文本节点,剋(kēi)成小块",
408+
explain: "仅对文本节点生效,根据标点符号,空格、换行符等进行分割,将其分割成小块",
409+
func() {
410+
const selectedTextNodes = StageManager.getSelectedEntities().filter((node) => node instanceof TextNode);
411+
for (const node of selectedTextNodes) {
412+
const text = node.text;
413+
const seps = [" ", "\n", "\t", ".", ",", ",", "。", "、", ";", ":", "?", "!"];
414+
415+
// 转义正则特殊字符
416+
const escapedSeps = seps.map((sep) => sep.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
417+
// 创建正则表达式,支持多个分隔符同时分割
418+
const regex = new RegExp(escapedSeps.join("|"), "g");
419+
// 分割后过滤空字符串
420+
const splitedTextList = text.split(regex).filter((item) => item !== "");
421+
// 将分割后的字符串添加到舞台
422+
const putLocation = node.collisionBox.getRectangle().location.clone();
423+
for (const splitedText of splitedTextList) {
424+
putLocation.y += 100;
425+
const newTextNode = new TextNode({
426+
uuid: v4(),
427+
text: splitedText,
428+
location: [putLocation.x, putLocation.y],
429+
size: [1, 1],
430+
color: node.color.clone().toArray(),
431+
// sizeAdjust: node.sizeAdjust,
432+
});
433+
StageManager.addTextNode(newTextNode);
434+
}
435+
}
436+
// 删除原来的文本节点
437+
StageManager.deleteEntities(selectedTextNodes);
438+
},
439+
},
406440

407441
// ====================
408442
// 以上是可能很方便的给用户用的

0 commit comments

Comments
 (0)