diff --git a/src/web-ui/src/flow_chat/components/ChatInput.tsx b/src/web-ui/src/flow_chat/components/ChatInput.tsx index f45eaba..d613ac3 100644 --- a/src/web-ui/src/flow_chat/components/ChatInput.tsx +++ b/src/web-ui/src/flow_chat/components/ChatInput.tsx @@ -551,10 +551,17 @@ export const ChatInput: React.FC = ({ } }, [currentSessionId, workspacePath, derivedState?.isProcessing]); - const handleInputChange = useCallback((text: string) => { + const handleInputChange = useCallback((text: string, activeContexts: import('../../shared/types/context').ContextItem[]) => { if (!inputState.isActive && text.length > 0) { dispatchInput({ type: 'ACTIVATE' }); } + + const activeContextIds = new Set(activeContexts.map(context => context.id)); + contexts.forEach(context => { + if (!activeContextIds.has(context.id)) { + removeContext(context.id); + } + }); dispatchInput({ type: 'SET_VALUE', payload: text }); @@ -578,7 +585,7 @@ export const ChatInput: React.FC = ({ }); } } - }, [derivedState, setQueuedInput, inputState.isActive, slashCommandState.isActive]); + }, [contexts, derivedState, inputState.isActive, removeContext, setQueuedInput, slashCommandState.isActive]); const handleSendOrCancel = useCallback(async () => { if (!derivedState) return; diff --git a/src/web-ui/src/flow_chat/components/RichTextInput.tsx b/src/web-ui/src/flow_chat/components/RichTextInput.tsx index 2442bde..2245d3f 100644 --- a/src/web-ui/src/flow_chat/components/RichTextInput.tsx +++ b/src/web-ui/src/flow_chat/components/RichTextInput.tsx @@ -302,13 +302,20 @@ export const RichTextInput = React.forwardRef('[data-context-id]') ?? []) + .map(element => element.dataset.contextId) + .filter((id): id is string => !!id) + ); + const visibleContexts = contexts.filter(context => visibleContextIds.has(context.id)); + + onChange(textContent, visibleContexts); // Ensure detection runs after DOM updates requestAnimationFrame(() => { detectMention(); }); - }, [contexts, onChange, detectMention]); + }, [contexts, onChange, detectMention, internalRef]); const handlePaste = useCallback((e: React.ClipboardEvent) => { e.preventDefault();