Skip to content

fix(prompt-templates): merge a template into the prompt and copy from the merged view - #10427

Merged
joshistoast merged 5 commits into
mainfrom
selectable-prompt-preview
Dec 3, 2026
Merged

joshistoast merged 5 commits into
mainfrom
selectable-prompt-preview

Conversation

@joshistoast

@joshistoast joshistoast commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

User feedback: in the legacy UI you could copy a template's text into the prompt box, then edit it or stack another template on top. Here you could only look at the merged prompt, and clicking it anywhere left the view.

  • Merge into prompt. The Templates popover gets a header for the applied template with Preview, Merge into prompt and Stop using. Merge writes the merged text into the prompt (and the negative prompt, if the template has negative text), stops using the template and offers an Undo. The text is then the user's to edit, and another template can be applied on top.
  • Copy from the merged view. Dragging over the read-only merged prompt now selects it, grey template words included, in both prompt boxes. A plain click still returns to editing.
  • Tidier prompt toolbar. The eye button moves into the popover, so an applied template adds no extra toolbar buttons. The Templates button shows an eye while the merged view is on, and its name shrinks before the other actions in a narrow panel.
  • Fix: in the merged view the Add prompt trigger (+) button was turned off by marking it open, which painted it pressed. It is now a disabled button.
  • Fix: Generate's merge reads the negative prompt after flushing drafts, as Upscale already did, so typing from the last moment is not overwritten.

Related Issues / Discussions

User feedback; no GitHub issue.

QA Instructions

In Generate (the Upscale panel's Detail guidance shares the same field):

  1. Type a prompt, open Templates and apply a template. The toolbar shows only the template's name.
  2. Open Templates again and click Preview. The prompt boxes show the merged prompt read-only, the Templates button shows an eye, and + is disabled without a pressed background.
  3. Drag across the merged text and copy it. The view stays. Click the text once: you are back to editing.
  4. Open Templates and click Merge into prompt. The merged text is in the prompt (and negative prompt), no template is applied, focus is in the prompt, and the notification's Undo restores the prompt, negative prompt and template.
  5. Apply a second template on top of the merged text.

Toolbar with a template applied:

Prompt toolbar with a template applied

Templates popover with the applied template's header:

Templates popover with the applied template header

Merged view, with the eye on the Templates button and + disabled:

Merged view of the prompt

Checks run locally (Node 22.14, invokeai/frontend/webv2), pnpm check:release:

  • Lint, types and architecture checks: pass.
  • Unit tests: 11,255 pass. Fixtures and the performance gates (build and browser): pass.
  • Browser suite: 3,535 pass, 1 failure in src/platform/ui/Menu.browser.test.tsx (a pointer-hover timeout in a file this PR does not touch); that file passes 25/25 when run alone.
  • Journeys (project files, accessibility, three-engine smoke): pass, run separately because the gate stops at the first failure.

Manually exercised in headless Chromium against the mock backend, Generate panel only. Not checked by hand: Firefox and WebKit, touch input, long or translated button labels wrapping in the popover header, and the Upscale panel (covered by UpscaleSharedPrompt.browser.test.tsx).

Review

Resolved: a click on already-selected text did not return to editing (the browser collapses the selection only after the click); the Generate merge could overwrite very recent negative-prompt typing; the Templates button could shrink below its icon; the popover's actions did not name the template for assistive technology; merge had no Undo coverage.

Remaining limits:

  • Double-click and triple-click in the merged view still return to editing, because the first click counts as a plain click. Drag, Shift+click and keyboard selection keep the view.
  • The docs images of the merged view and the Templates popover predate this layout; the guide's text is updated.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Meaningful regression coverage added / updated where needed; obsolete tests/code removed
  • Persisted-state and API changes include required migrations / compatibility validation
  • Relevant performance/efficiency opportunities considered; material claims have evidence
  • Material review findings resolved and relevant checks rerun
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…lected

A click in the read-only merged view used to return to editing, so the template's words could not be dragged over and copied.
A click now leaves the view only when the gesture selected nothing; the positive and negative prompt boxes share the rule.
… merged view

The merged view turned Add prompt trigger off by marking it open, which set aria-expanded and painted it pressed.
It is now a disabled button in both prompt boxes.
…plates popover

The popover's header names the applied template and holds Preview, Merge into prompt and Stop using; the toolbar's eye button is gone and the Templates button shows an eye while the merged view is on.
Merge writes the merged text into the prompt and negative prompt, stops using the template and offers an Undo; Generate reads the negative prompt after flushing drafts.
The applied template's name shrinks before the toolbar's other actions in a narrow panel.
@github-actions github-actions Bot added frontend PRs that change frontend files docs labels Nov 30, 2026
@Pfannkuchensack Pfannkuchensack self-assigned this Nov 30, 2026
@Pfannkuchensack Pfannkuchensack changed the title feat(prompt-templates): merge a template into the prompt and copy from the merged view fix(prompt-templates): merge a template into the prompt and copy from the merged view Nov 30, 2026

@Pfannkuchensack Pfannkuchensack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this works as described. I found no blockers. The merge goes through commitWithUndo as a whole, so one Undo restores the positive and negative prompts, the template and the view mode together. Generate now flushes its drafts before it reads the negative prompt, as Upscale already did. All the new en.json keys are used, clearApplied has no references left, and the prompting guide matches the code.

Locally tsc --noEmit and oxlint on promptFields are clean. The browser tests pass: 34 in the four changed files and 98 in all of promptFields.

Medium

The Generate merge has no test. The only merge test is in UpscaleSharedPrompt.browser.test.tsx. The fix in GeneratePromptFields.tsx (flushGenerateDrafts() and then a fresh readGenerateValues for the negative prompt) can be reverted without any test failing. Scenario: someone types in the negative prompt and clicks Merge into prompt within the debounce window. A Generate-side test that does exactly that, plus one with a template that has no negative text (the negative prompt has to stay as it is), would cover it.

Low

  • Untested paths:
    • Applying a second template after a merge. This works only because promptTemplate is null after the merge.
    • The new onExitMergedView path in NegativePromptField. The click logic is only tested through PositivePromptField.
  • Leaving Preview with the keyboard now takes more steps. The eye button moved into the popover. A keyboard user has to Tab to Templates, open it and choose to go back to editing. Enter in the read-only textarea fires no click. That is acceptable, and focus does return to the prompt, but the one-Tab toggle is gone.

Nits

  • flattenPromptTemplate flushes the drafts twice: once explicitly and again inside commitWithUndo. It is harmless.
  • Re-dragging exactly the same range in the merged view also leaves Preview, because handleClick only compares the selection with the one at mousedown.

Not checked: Firefox/WebKit, touch long-press selection, and long translated labels in the popover header.

… a template without negative text

Merging such a template appended a trailing space to the negative prompt; it now leaves it unchanged, as the merged view shows it.
Covers Generate's merge reading negative-prompt typing the debounce still holds, and regenerates the docs search index for the prompting guide.
@joshistoast

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Addressed in 1e1540c.

Medium: Generate merge test. Added to GenerateSettingsForm.browser.test.tsx: it holds the debounce, types into the negative prompt, clicks Merge into prompt, and checks both prompts carry the typing. With the old read restored, it fails ("blurry, lowres" instead of "blurry, grainy, lowres").

The no-negative-text case you suggested turned up a bug: applyPromptTemplate('', 'blurry') returns 'blurry ', so merging such a template added a trailing space to the negative prompt. flattenPromptTemplateExpansion now leaves the negative prompt as typed when the template has no negative text, as the merged view already shows it. Covered in promptTemplates.test.ts, since the rule lives in the core helper that Generate and Upscale share.

The commit also regenerates docsSearchIndex.json, which the prompting guide change had left stale (the failing check-and-build).

Low and nits, left as is:

  • Second template after a merge, and the negative field's onExitMergedView: no new tests. Each is one line of wiring over behavior already covered (applying a template; the click rule through PromptTextarea via the positive field). The package keeps one test per behavior.
  • Keyboard exit from Preview: agreed it is acceptable, left as is.
  • Double flush: the explicit flush is needed because the negative prompt is read before commitWithUndo runs its own flush. Upscale's merge has the same shape.
  • Re-dragging the exact same range: kept as a known limit. Telling it apart would mean tracking pointer movement for a rare gesture.

Checked on macOS: pnpm lint passes; generation unit tests pass (1,376); the Generate settings, prompt fields and Upscale shared-prompt browser tests pass except one Ctrl+Up/Down test in ResizableTextareaIntegration, which fails the same way on the unchanged branch (macOS key naming). Not run: the full release check, Firefox and WebKit.

@blacksmith-sh

This comment has been minimized.

…n it

The virtualized list mounts before it measures its viewport, so on a slow runner the test read the list while it held no rows.

@Pfannkuchensack Pfannkuchensack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked 1e1540c and f3de08e. The new Generate test covers the Medium: negative typing still held by the debounce ends up in the merged prompt. A template without negative text now leaves the negative prompt as typed, and a unit test covers it. The notifications test now waits for a real row, and CI is green. Approving.

The two untested paths from my last comment (a second template after a merge, onExitMergedView in the negative field) are still open. They don't block this.

@joshistoast
joshistoast added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit 910a056 Dec 3, 2026
34 checks passed
@joshistoast
joshistoast deleted the selectable-prompt-preview branch December 3, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0.0 docs frontend PRs that change frontend files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants