复用引用节点插入逻辑

统一资源与 Skill 候选的 Lexical 节点插入流程

避免两个选择处理器在删除查询和关闭菜单行为上漂移
This commit is contained in:
2026-09-15 19:52:55 +08:00
parent ea141c2ca1
commit 1c8d818ee0
@@ -858,41 +858,15 @@ function ResourceReferenceEditor({
[editor, pickerOpen],
);
const handleSelectMention = useCallback(
const insertReferenceNode = useCallback(
(
option: ResourceMentionOption,
reference: ChatReference,
textNodeContainingQuery: TextNode | null,
closeMenu: () => void,
) => {
textNodeContainingQuery?.remove();
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.insertNodes([
$createResourceReferenceNode(option.reference),
$createTextNode(' '),
]);
} else {
const paragraph = $createParagraphNode();
paragraph.append(
$createResourceReferenceNode(option.reference),
$createTextNode(' '),
);
$getRoot().append(paragraph);
}
closeMenu();
},
[],
);
const handleSelectSkill = useCallback(
(
option: SkillMentionOption,
textNodeContainingQuery: TextNode | null,
closeMenu: () => void,
) => {
textNodeContainingQuery?.remove();
const selection = $getSelection();
const node = $createResourceReferenceNode(option.skill);
const node = $createResourceReferenceNode(reference);
if ($isRangeSelection(selection)) {
selection.insertNodes([node, $createTextNode(' ')]);
} else {
@@ -905,6 +879,28 @@ function ResourceReferenceEditor({
[],
);
const handleSelectMention = useCallback(
(
option: ResourceMentionOption,
textNodeContainingQuery: TextNode | null,
closeMenu: () => void,
) => {
insertReferenceNode(option.reference, textNodeContainingQuery, closeMenu);
},
[insertReferenceNode],
);
const handleSelectSkill = useCallback(
(
option: SkillMentionOption,
textNodeContainingQuery: TextNode | null,
closeMenu: () => void,
) => {
insertReferenceNode(option.skill, textNodeContainingQuery, closeMenu);
},
[insertReferenceNode],
);
// —— C8 AI 润色与发送前提醒 ——
// 润色状态机抽到 `usePromptPolish`(资源侧两处入口共用同一份);这里只剩下
// 聊天特有的「发送前提醒」:提醒偏好、本轮已确认草稿指纹与表单拦截。