fix(web): let paste expand a resting composer (#9498)

Co-authored-by: Claude Code <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Code authored and GitHub committed 2026-09-03 17:04:39 -07:00
1 parent f8a14b28ff
commit 6382268323
1 file changed
+45 -5
+45 -5
View File
@@ -571,14 +571,24 @@ function eventPathContainsSelector(event: Event, selector: string): boolean {
return path.some((target) => target instanceof Element && target.closest(selector));
}
function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
if (event.defaultPrevented || event.isComposing) return false;
if (event.metaKey || event.ctrlKey || event.altKey) return false;
if (event.key.length !== 1) return false;
/**
* Whether input that landed outside any editable or interactive element
* should be redirected into the composer. Shared by type-to-focus and
* paste-to-focus so both honour the same surfaces.
*/
function shouldRedirectInputToComposer(event: Event): boolean {
if (event.defaultPrevented) return false;
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_EDITABLE_SELECTOR)) return false;
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_INTERACTIVE_SELECTOR)) return false;
if (document.querySelector(TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR)) return false;
return true;
}
function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
if (event.isComposing) return false;
if (event.metaKey || event.ctrlKey || event.altKey) return false;
if (event.key.length !== 1) return false;
if (!shouldRedirectInputToComposer(event)) return false;
// The right-panel surface launcher claims its shortcut letters while it is
// visible (data attribute set in RightPanelTabs); those keys open surfaces
@@ -591,6 +601,17 @@ function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
return true;
}
/**
* Plain text pasted with nothing editable focused, such as after the resting
* composer blurred. Files are left to the composer's own paste handler.
*/
function pasteTextToFocusComposer(event: ClipboardEvent): string | null {
if (!event.clipboardData || event.clipboardData.files.length > 0) return null;
if (!shouldRedirectInputToComposer(event)) return null;
const text = event.clipboardData.getData("text/plain");
return text.length > 0 ? text : null;
}
function formatOutgoingPrompt(params: {
provider: ProviderDriverKind;
model: string | null;
@@ -5859,6 +5880,25 @@ function ChatViewContent(props: ChatViewProps) {
composerRef,
]);
// Paste-to-focus: the resting composer blurs on a click into the timeline,
// so a paste that follows has no editable target and would be dropped.
// Route it to the composer like a typed key, which also expands it.
useEffect(() => {
const handler = (event: ClipboardEvent) => {
if (!activeThreadId || isCommandPaletteOpen()) return;
if (getTerminalFocusOwner() !== null) return;
if (composerRef.current?.isModelPickerOpen()) return;
const text = pasteTextToFocusComposer(event);
if (text === null) return;
if (composerRef.current?.insertTextAtEnd(text)) {
event.preventDefault();
event.stopPropagation();
}
};
window.addEventListener("paste", handler, true);
return () => window.removeEventListener("paste", handler, true);
}, [activeThreadId, composerRef]);
const onRevertToTurnCount = useCallback(
async (turnCount: number) => {
const localApi = readLocalApi();