fix: Optimized the scan node logic

This commit is contained in:
Gabe
2025-10-24 21:37:26 +08:00
parent ef07a172a9
commit 48ad100a64

View File

@@ -789,15 +789,24 @@ export class Translator {
}
const hasText = Translator.hasTextNode(rootNode);
if (hasText) {
this.#startObserveNode(rootNode);
if (!hasText && rootNode.children.length === 1) {
this.#scanNode(rootNode.children[0]);
return;
}
let hasBlock = false;
for (const child of rootNode.children) {
if (!hasText || Translator.isBlockNode(child)) {
const isBlock = Translator.isBlockNode(child);
if (isBlock) {
hasBlock = true;
this.#scanNode(child);
}
}
if (hasText || !hasBlock) {
this.#startObserveNode(rootNode);
}
}
// 处理一个待翻译的节点