Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/web-ui/src/flow_chat/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,17 @@ export const ChatInput: React.FC<ChatInputProps> = ({
}
}, [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 });

Expand All @@ -578,7 +585,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
});
}
}
}, [derivedState, setQueuedInput, inputState.isActive, slashCommandState.isActive]);
}, [contexts, derivedState, inputState.isActive, removeContext, setQueuedInput, slashCommandState.isActive]);

const handleSendOrCancel = useCallback(async () => {
if (!derivedState) return;
Expand Down
11 changes: 9 additions & 2 deletions src/web-ui/src/flow_chat/components/RichTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,20 @@ export const RichTextInput = React.forwardRef<HTMLDivElement, RichTextInputProps
if (isComposingRef.current) return;

const textContent = extractTextContent();
onChange(textContent, contexts);
const visibleContextIds = new Set(
Array.from(internalRef.current?.querySelectorAll<HTMLElement>('[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();
Expand Down
Loading