Skip to content

Switch styled element by clicking while the Style panel is open#468

Merged
aidenybai merged 3 commits into
mainfrom
cursor/edit-mode-element-switching-6b18
Jun 13, 2026
Merged

Switch styled element by clicking while the Style panel is open#468
aidenybai merged 3 commits into
mainfrom
cursor/edit-mode-element-switching-6b18

Conversation

@aidenybai

@aidenybai aidenybai commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

While the Style (edit) panel is open, clicking another element on the page now switches the editing session to that element instead of dismissing the panel. Edits compound across elements within a single session:

  • Switching keeps applied styles. The previous element's inline style preview stays on the page, and its pending edits are accumulated into the session.
  • Copy emits all edits. Submitting (Enter / Copy button) formats one prompt entry per styled element, merged by element identity (re-visiting an element merges its edits instead of duplicating the entry).
  • Discard reverts everything. Confirming the discard prompt (or dismissing on a non-grabbable target) restores every element styled during the session, in reverse order so re-visited elements unwind correctly.
  • The discard prompt and header Copy button stay armed after switching, even when the current element has no tweaks yet, as long as the session holds edits from previous elements.

Implementation

  • core/edit-mode.ts: the controller now tracks per-visit session records (element, preview, edits, source location) and exposes switchToElement plus setPendingEdits. Prompt formatting moved here from the panel so the compound prompt is built from the whole session. The new element's source path is resolved asynchronously since the store's selection source still points at the previous element.
  • core/index.tsx: window pointerdown while the panel is open resolves a grabbable element under the cursor and switches to it (consuming the gesture); the follow-up click is suppressed so page buttons/links don't activate when picked.
  • components/edit-panel/index.tsx: reports pending edits to the controller on every commit, gates dismiss/submit affordances on session edits, and no longer clears preview baselines on unmount (the controller owns restore-on-discard across switches).
  • utils/preview-styles.ts: removed the now-unused forget.

Testing

  • New e2e tests in edit-panel.spec.ts ("Element switching"): switch keeps applied styles and retargets tweaks; compound copy produces two CSS blocks; discard restores all elements; discard prompt stays armed after switching with no new tweaks.
  • Full suite: pnpm test (658 passed, 1 unrelated flaky that passes in isolation), pnpm lint, pnpm typecheck, pnpm format all green.
Open in Web Open in Cursor 

Summary by cubic

Switch the styled element by clicking another element while the Style panel is open. Edits persist across elements so you can copy or discard the whole session at once, and copy now reverts preview‑only elements to avoid stray inline styles.

  • New Features

    • Click another element to switch the style target without closing the panel; follow-up clicks are suppressed so links/buttons don’t fire.
    • Applied inline style previews stay visible when switching.
    • Copy emits one prompt entry per styled element; re-visits merge edits; file:line headers resolve even after fast switches.
    • Copy reverts switched-away elements with no net edits, preventing leftover inline styles.
    • Discard restores every element touched in the session, in correct order.
    • Discard prompt and header Copy button stay enabled if the session has prior edits.
  • Migration

    • onEditPanelSubmit now receives PendingEdits instead of a formatted prompt.
    • New: onEditPanelPendingEditsChange reports live PendingEdits.
    • PreviewStyles.forget() was removed.

Written for commit 739dfa4. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-grab-storybook Ready Ready Preview, Comment Jun 13, 2026 10:05am
react-grab-website Ready Ready Preview, Comment Jun 13, 2026 10:05am

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@react-grab/cli@468
npm i https://pkg.pr.new/grab@468
npm i https://pkg.pr.new/react-grab@468

commit: 739dfa4

@aidenybai aidenybai marked this pull request as ready for review June 13, 2026 02:32
Comment thread packages/react-grab/src/core/index.tsx

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/react-grab/src/core/edit-mode.ts Outdated
Comment thread packages/react-grab/src/core/index.tsx
cursoragent and others added 2 commits June 13, 2026 02:42
…is open

Clicking another element on the page while the edit (Style) panel is open
now switches the edit session to that element instead of dismissing the
panel. Applied inline styles are kept when switching, the session compounds
edits across elements, copying emits one prompt entry per styled element,
and discarding restores every element touched during the session.

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
switchToElement resolves an element's source asynchronously, so a fast
switch could bank a session record (or submit) before resolution landed,
emitting a CSS block with no file:line header for that element. Patch any
already-recorded visit when resolution arrives (not just live state) and
prefer a non-empty source when merging a revisited element's entries.

Also dedupe the session-record construction via a shared helper and drop
the now-unused CARD_SELECTOR test export.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4b5084a. Configure here.

Comment thread packages/react-grab/src/core/edit-mode.ts Outdated

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additional Suggestion:

On touch devices, the registerOverlayDismiss handler (which listens to touchstart) fires before pointerdown. If there are no pending edits and the user taps a grabbable element, the panel dismisses before switchToElement can execute, preventing element switching.

Fix on Vercel

Comment thread packages/react-grab/src/core/edit-mode.ts
A switched-away element can bank a session record with no net edits but
live preview styles (tweaked then stepped back to original). Those never
reach the copied prompt, yet submit's clearAll dropped them without
restoring, leaving stray inline styles on the page that the copy never
described — unlike discard, which restores them. Submit now reverts any
banked visit whose element contributed no edits to the prompt.

Adds an e2e covering copy after a switched-away element's tweak is undone.
@aidenybai aidenybai merged commit a87d070 into main Jun 13, 2026
18 checks passed
@aidenybai aidenybai deleted the cursor/edit-mode-element-switching-6b18 branch June 13, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants