diff --git a/web/src/components/deer-flow/message-input.tsx b/web/src/components/deer-flow/message-input.tsx index 0a68fb8..b3f6cd2 100644 --- a/web/src/components/deer-flow/message-input.tsx +++ b/web/src/components/deer-flow/message-input.tsx @@ -21,7 +21,6 @@ import "~/styles/prosemirror.css"; import { resourceSuggestion } from "./resource-suggestion"; import React, { forwardRef, useEffect, useMemo, useRef } from "react"; import type { Resource } from "~/core/messages"; -import { useConfig } from "~/core/api/hooks"; import { LoadingOutlined } from "@ant-design/icons"; import type { DeerFlowConfig } from "~/core/config"; diff --git a/web/src/components/deer-flow/resource-suggestion.tsx b/web/src/components/deer-flow/resource-suggestion.tsx index a8aa501..4934f32 100644 --- a/web/src/components/deer-flow/resource-suggestion.tsx +++ b/web/src/components/deer-flow/resource-suggestion.tsx @@ -35,17 +35,26 @@ export const resourceSuggestion: MentionOptions["suggestion"] = { return { onStart: (props) => { - if (!props.clientRect) { - return; - } - reactRenderer = new ReactRenderer(ResourceMentions, { props, editor: props.editor, }); + const clientRect = props.clientRect || (() => { + const selection = props.editor.state.selection; + const coords = props.editor.view.coordsAtPos(selection.from); + return { + top: coords.top, + left: coords.left, + right: coords.right, + bottom: coords.bottom, + width: 0, + height: 0, + }; + }); + popup = tippy("body", { - getReferenceClientRect: props.clientRect as any, + getReferenceClientRect: clientRect as any, appendTo: () => document.body, content: reactRenderer.element, showOnCreate: true, @@ -56,15 +65,28 @@ export const resourceSuggestion: MentionOptions["suggestion"] = { }, onUpdate(props) { - reactRenderer.updateProps(props); - - if (!props.clientRect) { - return; + if (reactRenderer) { + reactRenderer.updateProps(props); } - popup?.[0]?.setProps({ - getReferenceClientRect: props.clientRect as any, - }); + if (popup?.[0] && !popup[0].state.isDestroyed) { + const clientRect = props.clientRect || (() => { + const selection = props.editor.state.selection; + const coords = props.editor.view.coordsAtPos(selection.from); + return { + top: coords.top, + left: coords.left, + right: coords.right, + bottom: coords.bottom, + width: 0, + height: 0, + }; + }); + + popup[0].setProps({ + getReferenceClientRect: clientRect as any, + }); + } }, onKeyDown(props) {