过滤 DirectProject 编辑器的空白内容 part
跳过纯空白文本节点并合并相邻文本,避免引用后的分隔空格和换行触发 Rust 空输入校验。
This commit is contained in:
+14
-3
@@ -183,6 +183,17 @@ function sameDraft(left: ChatComposerDraft, right: ChatComposerDraft) {
|
||||
);
|
||||
}
|
||||
|
||||
function appendInputText(content: DirectCodexUserContentPart[], text: string) {
|
||||
const previous = content[content.length - 1];
|
||||
if (previous?.type === 'input_text') {
|
||||
previous.text += text;
|
||||
return;
|
||||
}
|
||||
if (text.trim()) {
|
||||
content.push({ type: 'input_text', text });
|
||||
}
|
||||
}
|
||||
|
||||
function collectDraftParts(
|
||||
node: LexicalNode,
|
||||
textParts: string[],
|
||||
@@ -192,12 +203,12 @@ function collectDraftParts(
|
||||
if ($isTextNode(node)) {
|
||||
const text = node.getTextContent();
|
||||
textParts.push(text);
|
||||
if (text) content.push({ type: 'input_text', text });
|
||||
appendInputText(content, text);
|
||||
return;
|
||||
}
|
||||
if ($isLineBreakNode(node)) {
|
||||
textParts.push('\n');
|
||||
content.push({ type: 'input_text', text: '\n' });
|
||||
appendInputText(content, '\n');
|
||||
return;
|
||||
}
|
||||
if ($isResourceReferenceNode(node)) {
|
||||
@@ -210,7 +221,7 @@ function collectDraftParts(
|
||||
node.getChildren().forEach((child, index) => {
|
||||
if (index > 0 && node.getType() === 'root') {
|
||||
textParts.push('\n');
|
||||
content.push({ type: 'input_text', text: '\n' });
|
||||
appendInputText(content, '\n');
|
||||
}
|
||||
collectDraftParts(child, textParts, references, content);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user