From 48ad100a6473458e86aa04959f54f021dd2b2707 Mon Sep 17 00:00:00 2001 From: Gabe Date: Fri, 24 Oct 2025 21:37:26 +0800 Subject: [PATCH] fix: Optimized the scan node logic --- src/libs/translator.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libs/translator.js b/src/libs/translator.js index efd10e5..d57be34 100644 --- a/src/libs/translator.js +++ b/src/libs/translator.js @@ -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); + } } // 处理一个待翻译的节点