[PR #7591] [MERGED] fix(chat): keep the expanded editor open when a Grammarly suggestion is applied #7820

Closed
opened 2026-10-24 04:07:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7591
Author: @SpicyMarinara
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/expanded-editor-grammarly


📝 Commits (2)

  • c0eecde fix(chat): keep the expanded editor open when a Grammarly suggestion is applied
  • 64ed7f4 fix(chat): keep Edit Summaries and preset value editors open on Escape in a Grammarly card

📊 Changes

7 files changed (+282 additions, -4 deletions)

View changed files

➕ e2e/extension-ui-presses.e2e.ts (+244 -0)
📝 packages/client/src/components/chat/SummariesEditorModal.tsx (+3 -1)
📝 packages/client/src/components/presets/PresetVariablesEditor.tsx (+3 -1)
📝 packages/client/src/components/ui/ExpandedTextarea.tsx (+3 -1)
📝 packages/client/src/components/ui/FloatingWindow.tsx (+3 -0)
📝 packages/client/src/components/ui/MacroTextarea.tsx (+3 -1)
📝 packages/client/src/lib/chat-floating-ui-events.ts (+23 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

No linked issue: reported by the maintainer on 2026-10-14.

Why this change

  • On a computer, editing a summary in the expanded Chat Summary editor and clicking a Grammarly suggestion to apply it closed the whole Chat Settings window. The expanded editor went with it, along with the summary edit that had not been saved yet.
  • Cause: Grammarly shows its suggestion cards outside the app, in a <grammarly-popups> custom element with an open shadow root that it appends to <html>. This was checked against the source of the installed Grammarly Chrome extension (14.1329.0). Clicking "accept" there looked like a press elsewhere to the shared floating-window handler (FloatingWindow.tsx, the outside pointerdown listener that calls requestClose("outside-pointer")). That closed the unpinned Chat Settings window and unmounted the editor inside it. A pinned window stayed open, which confirmed this handler as the cause.
    • Grammarly puts the card inside an open modal <dialog> instead only behind one of its experiment flags. The app uses no <dialog> elements, so that case can't come up here.
    • Moving focus into the card, the browser window losing focus, and Grammarly's input events closed nothing.
    • Escape pressed while focus was inside the card did close the expanded editor. It also closed the conversation Edit Summaries editor, which dropped its unsaved drafts, and a preset variable's expanded value editor.

What changed

  • Applying a Grammarly suggestion (or using any other extension card that sits outside the app) no longer closes Chat Settings, a popped-out drawer or any other chat window. The editor stays open, and the fix lands in the text you're editing. This covers the expanded Chat Summary editor and the conversation Edit Summaries editor, which both live in Chat Settings.
  • Pressing Escape inside such an extension card closes the card only. These editors stay open:
    • the expanded editor of a summary entry or other prompt field;
    • the conversation Edit Summaries editor, with its unsaved drafts;
    • a preset variable's expanded value editor.
  • These still work the same: clicking the chat or elsewhere in the app closes an unpinned window, and pressing Escape in an editor itself closes it as before.
  • Technical: a new shared helper, isBrowserExtensionUi(target) in lib/chat-floating-ui-events.ts. It steps out of shadow roots, then climbs to the element added directly to <body> or <html>. It returns true for anything added to <html> and for a custom element (a tag name with a hyphen) under <body>. The app's root and portals are plain elements, so they never match. No list of extension names is needed. These handlers ignore those targets:
    • FloatingWindow's outside-press handler;
    • the document Escape handlers of ExpandedMacroEditor (MacroTextarea.tsx), ExpandedTextarea, SummariesEditorModal and ExpandedEditorModal (PresetVariablesEditor.tsx).
  • A ponytail: note records the known limit: an extension that hosts its UI in a plain element under <body> still counts as outside.
  • New regression e2e/extension-ui-presses.e2e.ts (desktop Chromium). It injects a <grammarly-popups> card with an open shadow root and clicks its accept button with real pointer events. That applies the fix through execCommand("insertText").
    • Expanded Chat Summary editor: the card goes under <body> and then under <html>. The spec also moves focus into the card, sends a window blur (a smoke check only, since a synthetic blur fires no focusout on the field) and presses Escape in the card. It checks that the editor and Chat Settings stay open, that Escape in the editor still closes it, that the saved summary has both fixes, and that a click on the chat still closes Chat Settings.
    • Conversation Edit Summaries editor: it accepts a fix from the card and presses Escape in the card. It checks that Chat Settings and the editor stay open with the draft, and that Save keeps the fix.
    • Preset variable value editor: it accepts a fix and presses Escape in the card, then checks that the editor stays open. It also checks that Escape in the field still closes the editor and keeps the edit.
    • Each case fails without its fix.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agents:

  • playwright test --project=desktop-chromium e2e/extension-ui-presses.e2e.ts with the fixes removed:
    • Expanded summary case: failed on staging code. After the first accept, the expanded editor was gone.
    • Edit Summaries and preset value editor cases: failed without their Escape fixes. After Escape in the card, the editor was gone.
  • Same spec with the fixes: passed, including 5 runs in a row (15 of 15).
  • A temporary exploration spec (deleted, not committed) tried each Grammarly-like action on its own against staging.
    • A click on the card under <body> closed the editor and Chat Settings, and so did a click on the card under <html>. With the window pinned, nothing closed.
    • Focus into the card, window blur and a synthetic input event closed nothing. Escape inside the card closed the expanded editor.
    • With the fix, nothing closed in any of these cases.
  • pnpm localization:check: passed. No new strings.
  • pnpm check: passed.
  • Related desktop Chromium specs, with one worker: the new spec plus chat-settings-window, drawer-popout, prompt-field-font, semantic-recall-controls and summary-controls. 36 passed, 4 skipped (the skips are project-gated). An earlier run of the first round also covered chat-control-windows, tracker-window and the matching core-flows cases.
  • pnpm smoke:ui: 7 passed.
  • Local CodeRabbit (coderabbit review --agent --committed --base-commit <merge-base>): review completed with 0 findings on both rounds.

Manual verification notes

Manual verification:

  • Manually verify on desktop with the Grammarly browser extension: open a chat's Chat Summary, edit an entry and open the expanded editor. Accept a Grammarly suggestion. The editor and Chat Settings should stay open, the fix should appear in the text, and Save should keep it.
  • Manually verify the same in a conversation chat: Chat Settings > Automatic Summarization > Edit Summaries, open a day, accept a Grammarly suggestion, then Save.
  • Manually verify with the Grammarly desktop app (macOS or Windows) if you have it. The agents could not test it. With the browser extension installed, Chrome uses the extension instead of the desktop app's overlay.
  • Manually verify that dismissing a Grammarly card (its close button, or Escape while the card has focus) leaves the editor open.
  • Manually verify that clicking the chat, or elsewhere in the app, outside an unpinned Chat Settings window still closes it. Escape in the expanded editor should still close the editor and keep the edit.
  • Manually verify the same accept-a-suggestion flow in a popped-out Chat Summary window and in another expanded editor inside Chat Settings, for example Scene instructions.
  • Optional: repeat with another grammar or password-manager extension (LanguageTool, 1Password) whose popups sit outside the app.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No visual change. The regression spec covers the behaviour.

Summary by CodeRabbit

  • Bug Fixes
    • Browser-extension suggestion cards no longer accidentally close Chat Settings or expanded editors when clicked or when Escape is pressed.
    • Pressing Escape inside an expanded editor still closes it, and clicking the chat still closes Chat Settings.
    • Edits and drafts in expanded editors are preserved when interacting with suggestion cards and remain available to save.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7591 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/expanded-editor-grammarly` --- ### 📝 Commits (2) - [`c0eecde`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c0eecdec3bb0c7c906e740242b07852d3eaa4248) fix(chat): keep the expanded editor open when a Grammarly suggestion is applied - [`64ed7f4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/64ed7f4102304390567cb39f3dc38cf5237e2c9a) fix(chat): keep Edit Summaries and preset value editors open on Escape in a Grammarly card ### 📊 Changes **7 files changed** (+282 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `e2e/extension-ui-presses.e2e.ts` (+244 -0) 📝 `packages/client/src/components/chat/SummariesEditorModal.tsx` (+3 -1) 📝 `packages/client/src/components/presets/PresetVariablesEditor.tsx` (+3 -1) 📝 `packages/client/src/components/ui/ExpandedTextarea.tsx` (+3 -1) 📝 `packages/client/src/components/ui/FloatingWindow.tsx` (+3 -0) 📝 `packages/client/src/components/ui/MacroTextarea.tsx` (+3 -1) 📝 `packages/client/src/lib/chat-floating-ui-events.ts` (+23 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> No linked issue: reported by the maintainer on 2026-10-14. ## Why this change <!-- What user problem, bug, or goal does this solve? --> - On a computer, editing a summary in the expanded Chat Summary editor and clicking a Grammarly suggestion to apply it closed the whole Chat Settings window. The expanded editor went with it, along with the summary edit that had not been saved yet. - Cause: Grammarly shows its suggestion cards outside the app, in a `<grammarly-popups>` custom element with an open shadow root that it appends to `<html>`. This was checked against the source of the installed Grammarly Chrome extension (14.1329.0). Clicking "accept" there looked like a press elsewhere to the shared floating-window handler (`FloatingWindow.tsx`, the outside `pointerdown` listener that calls `requestClose("outside-pointer")`). That closed the unpinned Chat Settings window and unmounted the editor inside it. A pinned window stayed open, which confirmed this handler as the cause. - Grammarly puts the card inside an open modal `<dialog>` instead only behind one of its experiment flags. The app uses no `<dialog>` elements, so that case can't come up here. - Moving focus into the card, the browser window losing focus, and Grammarly's input events closed nothing. - Escape pressed while focus was inside the card did close the expanded editor. It also closed the conversation **Edit Summaries** editor, which dropped its unsaved drafts, and a preset variable's expanded value editor. ## What changed <!-- List the key changes in this PR --> - Applying a Grammarly suggestion (or using any other extension card that sits outside the app) no longer closes Chat Settings, a popped-out drawer or any other chat window. The editor stays open, and the fix lands in the text you're editing. This covers the expanded Chat Summary editor and the conversation **Edit Summaries** editor, which both live in Chat Settings. - Pressing Escape inside such an extension card closes the card only. These editors stay open: - the expanded editor of a summary entry or other prompt field; - the conversation **Edit Summaries** editor, with its unsaved drafts; - a preset variable's expanded value editor. - These still work the same: clicking the chat or elsewhere in the app closes an unpinned window, and pressing Escape in an editor itself closes it as before. - Technical: a new shared helper, `isBrowserExtensionUi(target)` in `lib/chat-floating-ui-events.ts`. It steps out of shadow roots, then climbs to the element added directly to `<body>` or `<html>`. It returns true for anything added to `<html>` and for a custom element (a tag name with a hyphen) under `<body>`. The app's root and portals are plain elements, so they never match. No list of extension names is needed. These handlers ignore those targets: - `FloatingWindow`'s outside-press handler; - the document Escape handlers of `ExpandedMacroEditor` (`MacroTextarea.tsx`), `ExpandedTextarea`, `SummariesEditorModal` and `ExpandedEditorModal` (`PresetVariablesEditor.tsx`). - A `ponytail:` note records the known limit: an extension that hosts its UI in a plain element under `<body>` still counts as outside. - New regression `e2e/extension-ui-presses.e2e.ts` (desktop Chromium). It injects a `<grammarly-popups>` card with an open shadow root and clicks its accept button with real pointer events. That applies the fix through `execCommand("insertText")`. - **Expanded Chat Summary editor:** the card goes under `<body>` and then under `<html>`. The spec also moves focus into the card, sends a window `blur` (a smoke check only, since a synthetic `blur` fires no `focusout` on the field) and presses Escape in the card. It checks that the editor and Chat Settings stay open, that Escape in the editor still closes it, that the saved summary has both fixes, and that a click on the chat still closes Chat Settings. - **Conversation Edit Summaries editor:** it accepts a fix from the card and presses Escape in the card. It checks that Chat Settings and the editor stay open with the draft, and that Save keeps the fix. - **Preset variable value editor:** it accepts a fix and presses Escape in the card, then checks that the editor stays open. It also checks that Escape in the field still closes the editor and keeps the edit. - Each case fails without its fix. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agents: - `playwright test --project=desktop-chromium e2e/extension-ui-presses.e2e.ts` with the fixes removed: - Expanded summary case: **failed** on `staging` code. After the first accept, the expanded editor was gone. - Edit Summaries and preset value editor cases: **failed** without their Escape fixes. After Escape in the card, the editor was gone. - Same spec with the fixes: **passed**, including 5 runs in a row (15 of 15). - A temporary exploration spec (deleted, not committed) tried each Grammarly-like action on its own against `staging`. - A click on the card under `<body>` closed the editor and Chat Settings, and so did a click on the card under `<html>`. With the window pinned, nothing closed. - Focus into the card, window `blur` and a synthetic `input` event closed nothing. Escape inside the card closed the expanded editor. - With the fix, nothing closed in any of these cases. - `pnpm localization:check`: passed. No new strings. - `pnpm check`: passed. - Related desktop Chromium specs, with one worker: the new spec plus `chat-settings-window`, `drawer-popout`, `prompt-field-font`, `semantic-recall-controls` and `summary-controls`. **36 passed, 4 skipped** (the skips are project-gated). An earlier run of the first round also covered `chat-control-windows`, `tracker-window` and the matching `core-flows` cases. - `pnpm smoke:ui`: **7 passed**. - Local CodeRabbit (`coderabbit review --agent --committed --base-commit <merge-base>`): review completed with **0 findings** on both rounds. ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> Manual verification: - Manually verify on desktop with the Grammarly browser extension: open a chat's Chat Summary, edit an entry and open the expanded editor. Accept a Grammarly suggestion. The editor and Chat Settings should stay open, the fix should appear in the text, and **Save** should keep it. - Manually verify the same in a conversation chat: Chat Settings > Automatic Summarization > **Edit Summaries**, open a day, accept a Grammarly suggestion, then **Save**. - Manually verify with the Grammarly desktop app (macOS or Windows) if you have it. The agents could not test it. With the browser extension installed, Chrome uses the extension instead of the desktop app's overlay. - Manually verify that dismissing a Grammarly card (its close button, or Escape while the card has focus) leaves the editor open. - Manually verify that clicking the chat, or elsewhere in the app, outside an unpinned Chat Settings window still closes it. Escape in the expanded editor should still close the editor and keep the edit. - Manually verify the same accept-a-suggestion flow in a popped-out Chat Summary window and in another expanded editor inside Chat Settings, for example Scene instructions. - Optional: repeat with another grammar or password-manager extension (LanguageTool, 1Password) whose popups sit outside the app. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> No visual change. The regression spec covers the behaviour. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Browser-extension suggestion cards no longer accidentally close Chat Settings or expanded editors when clicked or when Escape is pressed. * Pressing Escape inside an expanded editor still closes it, and clicking the chat still closes Chat Settings. * Edits and drafts in expanded editors are preserved when interacting with suggestion cards and remain available to save. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7820
No description provided.