Repository navigation
feat(composer): fullscreen edit mode and one-line collapse for long sent messages (fixes #351) #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import assert from "node:assert/strict"; | ||
| import "../tests/setup-dom.mjs"; | ||
| import test from "node:test"; | ||
| import React from "react"; | ||
|
|
||
| const { act, cleanup, fireEvent, render } = await import("@testing-library/react/pure.js"); | ||
| const { ChatInput } = await import("./ChatInput.tsx"); | ||
|
|
||
| // jsdom 29 ships no matchMedia, and the composer reads one at mount for the | ||
| // word-completion default (`(pointer: fine)`). Never match: desktop composer. | ||
| window.matchMedia = (media) => ({ | ||
| media, | ||
| matches: false, | ||
| onchange: null, | ||
| addEventListener() {}, | ||
| removeEventListener() {}, | ||
| addListener() {}, | ||
| removeListener() {}, | ||
| dispatchEvent() { return false; }, | ||
| }); | ||
|
|
||
| async function renderComposer(t, props = {}) { | ||
| const sent = []; | ||
| const view = render(React.createElement(ChatInput, { | ||
| async onSend(message) { sent.push(message); return { status: "accepted" }; }, | ||
| onThinkingLevelChange() {}, | ||
| thinkingLevel: "auto", | ||
| isStreaming: false, | ||
| ...props, | ||
| })); | ||
| t.after(() => cleanup()); | ||
| await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); }); | ||
| return { view, sent }; | ||
| } | ||
|
|
||
| const expandButton = (view) => view.getByRole("button", { name: /Expand editor|chatInput\.expandEditor/ }); | ||
|
|
||
| test("the composer opens a full-screen editor that shares its draft", async (t) => { | ||
| const { view } = await renderComposer(t); | ||
| assert.equal(view.queryByRole("dialog"), null, "the editor must start closed"); | ||
| fireEvent.click(expandButton(view)); | ||
| const dialog = view.getByRole("dialog"); | ||
| const editor = dialog.querySelector("textarea"); | ||
| assert.ok(editor, "the full-screen editor needs a textarea"); | ||
| fireEvent.change(editor, { target: { value: "a very long prompt\nwith many lines" } }); | ||
| assert.equal(editor.value, "a very long prompt\nwith many lines"); | ||
| // Done closes the editor and the compact composer keeps the same text. | ||
| // (The header ✕ shares the Done label; the footer button is the text one.) | ||
| fireEvent.click(view.getByText("Done")); | ||
| assert.equal(view.queryByRole("dialog"), null); | ||
| const [compact] = view.container.querySelectorAll("textarea"); | ||
| assert.equal(compact.value, "a very long prompt\nwith many lines"); | ||
| }); | ||
|
|
||
| test("Ctrl+Enter in the full-screen editor sends the draft", async (t) => { | ||
| const { view, sent } = await renderComposer(t); | ||
| fireEvent.click(expandButton(view)); | ||
| const editor = view.getByRole("dialog").querySelector("textarea"); | ||
| fireEvent.change(editor, { target: { value: "send me" } }); | ||
| fireEvent.keyDown(editor, { key: "Enter", ctrlKey: true }); | ||
| await act(async () => { await new Promise((resolve) => setTimeout(resolve, 50)); }); | ||
| assert.deepEqual(sent, ["send me"]); | ||
| assert.equal(view.queryByRole("dialog"), null, "sending closes the editor"); | ||
| }); | ||
|
|
||
| test("Escape closes the full-screen editor without sending", async (t) => { | ||
| const { view, sent } = await renderComposer(t); | ||
| fireEvent.click(expandButton(view)); | ||
| const editor = view.getByRole("dialog").querySelector("textarea"); | ||
| fireEvent.change(editor, { target: { value: "keep me" } }); | ||
| fireEvent.keyDown(editor, { key: "Escape" }); | ||
| assert.equal(view.queryByRole("dialog"), null); | ||
| assert.deepEqual(sent, []); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| import React, { useRef, useState, useCallback, useEffect, useLayoutEffect, useImperativeHandle, forwardRef, memo, KeyboardEvent } from "react"; | ||
| import { createPortal } from "react-dom"; | ||
| import { ChevronDown, ClipboardPaste, CornerDownRight, ListChecks, Loader2, Mic, Paperclip, Plus, RotateCw, Shrink, Snail, Sparkles, Terminal, Wrench, X, Zap } from "lucide-react"; | ||
| import { ChevronDown, ClipboardPaste, CornerDownRight, ListChecks, Loader2, Maximize2, Mic, Paperclip, Plus, RotateCw, Shrink, Snail, Sparkles, Terminal, Wrench, X, Zap } from "lucide-react"; | ||
| import { getSubmitDuringRunBehavior, isWordCompletionEnabled } from "@/lib/composer-prefs"; | ||
| import type { BuiltinSlashCommandResult, CompactResultInfo, PromptSendOptions, PromptSubmissionResult, QueuedMessages, SlashCommandInfo } from "@/hooks/useAgentSession"; | ||
| import type { ActiveGoal, ActivePlan } from "@/lib/web-mode-state"; | ||
|
|
@@ -457,6 +457,9 @@ export const ChatInput = memo(forwardRef<ChatInputHandle, Props>(function ChatIn | |
| const contextContainer = isMobile ? sessionInfoContainer : composerContextContainer; | ||
| const [plusMenuOpen, setPlusMenuOpen] = useState(false); | ||
| const [plusExpanded, setPlusExpanded] = useState<"tools" | "advisor" | null>(null); | ||
| // Full-screen editing surface for long prompts; shares the composer's draft | ||
| // value, so closing it (or sending from it) keeps the same text. | ||
| const [editorFullscreen, setEditorFullscreen] = useState(false); | ||
| const [modelSearchQuery, setModelSearchQuery] = useState(""); | ||
| const [attachedImages, setAttachedImages] = useState<AttachedImage[]>(() => ( | ||
| draftKey ? draftImagesToAttachedImages(getDraft(draftKey)?.images) : [] | ||
|
|
@@ -3965,6 +3968,27 @@ export const ChatInput = memo(forwardRef<ChatInputHandle, Props>(function ChatIn | |
| <Mic size={14} strokeWidth={1.8} aria-hidden="true" /> | ||
| </button> | ||
| )} | ||
| {/* Full-screen editor for long prompts */} | ||
| <button | ||
| type="button" | ||
| onClick={() => setEditorFullscreen(true)} | ||
| title={t("chatInput.expandEditor")} | ||
| aria-label={t("chatInput.expandEditor")} | ||
| style={{ | ||
| display: "flex", alignItems: "center", justifyContent: "center", | ||
| width: 28, height: 28, padding: 0, | ||
| background: "none", | ||
| border: "none", | ||
| borderRadius: 7, | ||
| color: "var(--text-muted)", | ||
| cursor: "pointer", | ||
| transition: "background var(--dur-fast) var(--ease-out-warm), color var(--dur-fast) var(--ease-out-warm)", | ||
| }} | ||
| onMouseEnter={(e) => { e.currentTarget.style.background = "var(--bg-hover)"; }} | ||
| onMouseLeave={(e) => { e.currentTarget.style.background = "none"; }} | ||
| > | ||
| <Maximize2 size={14} strokeWidth={1.8} aria-hidden="true" /> | ||
| </button> | ||
| {/* Primary action: Send (idle) / Steer or Queue (typed while running, per Settings) / Stop (running) */} | ||
| {primaryActionQueuesMessage ? ( | ||
| <button | ||
|
|
@@ -4064,6 +4088,86 @@ export const ChatInput = memo(forwardRef<ChatInputHandle, Props>(function ChatIn | |
|
|
||
|
|
||
| </div> | ||
| {editorFullscreen && createPortal( | ||
| <div | ||
| role="dialog" | ||
| aria-label={t("chatInput.fullscreenEditor")} | ||
| aria-modal="true" | ||
| style={{ | ||
| position: "fixed", inset: 0, zIndex: 100, | ||
| display: "flex", flexDirection: "column", | ||
| background: "var(--bg)", padding: "16px", | ||
| }} | ||
| > | ||
| <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 12 }}> | ||
| <span style={{ flex: 1, minWidth: 0, fontSize: 14, fontWeight: 600, color: "var(--text)" }}>{t("chatInput.fullscreenEditor")}</span> | ||
| <span style={{ fontSize: 12, color: "var(--text-dim)" }}>{t("chatInput.fullscreenEditorHint")}</span> | ||
| <button | ||
| type="button" | ||
| onClick={() => setEditorFullscreen(false)} | ||
| title={t("chatInput.doneEditing")} | ||
| aria-label={t("chatInput.doneEditing")} | ||
| style={{ | ||
| display: "flex", alignItems: "center", justifyContent: "center", | ||
| width: 32, height: 32, padding: 0, | ||
| background: "var(--bg-panel)", border: "1px solid var(--border)", | ||
| borderRadius: 8, color: "var(--text)", cursor: "pointer", | ||
| fontSize: 13, fontWeight: 600, | ||
| }} | ||
| > | ||
| <X size={14} strokeWidth={1.8} aria-hidden="true" /> | ||
| </button> | ||
| </div> | ||
| <textarea | ||
| autoFocus | ||
| value={value} | ||
| onChange={(e) => setValue(e.target.value)} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Escape") { e.stopPropagation(); setEditorFullscreen(false); } | ||
|
Comment on lines
+4125
to
+4126
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle Escape at the dialog boundary. If Done, Send, or the header close button has focus, Escape does not close the editor. The handler belongs only to the sibling textarea. Handle Escape on the dialog container so all dialog controls support the advertised shortcut. Retain the propagation guard.
|
||
| else if ((e.metaKey || e.ctrlKey) && e.key === "Enter") { e.preventDefault(); setEditorFullscreen(false); void handleSend(); } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore the submit shortcut during IME composition. If Ctrl/Cmd+Enter occurs with Apply the existing IME and composition-end safeguards before submitting. Preserve Ctrl/Cmd+Enter when composition is inactive. Based on learnings, Enter submission handlers must ignore IME confirmation.
|
||
| }} | ||
| placeholder={t("chatInput.placeholder")} | ||
| aria-label={t("chatInput.fullscreenEditor")} | ||
| style={{ | ||
| flex: 1, minHeight: 0, width: "100%", | ||
| background: "var(--bg-panel)", | ||
| border: "1px solid var(--border)", borderRadius: "var(--radius-card)", | ||
| outline: "none", resize: "none", | ||
| color: "var(--text)", | ||
| fontSize: "var(--chat-user-font-size)", | ||
| lineHeight: "var(--chat-line-height)", | ||
| fontFamily: "inherit", | ||
| padding: "12px 14px", | ||
| }} | ||
| /> | ||
| <div style={{ display: "flex", justifyContent: "flex-end", gap: 8, marginTop: 12 }}> | ||
| <button | ||
| type="button" | ||
| onClick={() => setEditorFullscreen(false)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore focus when the editor closes. Done removes the focused dialog control without restoring focus. The header close button and Escape have the same problem. Keyboard users lose their position in the composer. Capture the opening control and restore focus after the dialog unmounts. Apply this to every close path. Based on learnings, modal dialogs must restore focus when they close.
|
||
| style={{ | ||
| display: "flex", alignItems: "center", height: 32, padding: "0 14px", | ||
| background: "var(--bg-panel)", border: "1px solid var(--border)", borderRadius: 8, | ||
| color: "var(--text)", cursor: "pointer", fontSize: 13, fontWeight: 600, | ||
| }} | ||
| > | ||
| {t("chatInput.doneEditing")} | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => { setEditorFullscreen(false); void handleSend(); }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve send-during-run dispatch in fullscreen mode. If Use the same dispatch for both fullscreen submission controls. Keep direct submission when the agent is idle.
|
||
| disabled={submissionBlocked || !(value.trim() || hasAttachments)} | ||
| style={{ | ||
| display: "flex", alignItems: "center", height: 32, padding: "0 14px", | ||
| background: "var(--accent-strong)", border: "none", borderRadius: 8, | ||
| color: "var(--on-accent)", cursor: "pointer", fontSize: 13, fontWeight: 600, | ||
| }} | ||
| > | ||
| {t("chatInput.send")} | ||
| </button> | ||
| </div> | ||
| </div>, | ||
| document.body, | ||
| )} | ||
| </div> | ||
| ); | ||
| })); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contain keyboard focus inside the modal.
autoFocusmoves focus into the textarea, but Tab navigation can leave the dialog. For example, Shift+Tab from the header close button reaches background controls.aria-modaldoes not prevent this.Use a modal primitive or add focus containment and make the background inert while the editor is open. Based on learnings, modal overlays must contain keyboard focus.
Source: Learnings