Skip to content

Extract shared image clipboard copy utility - #31600

Merged
AmethystLiang merged 2 commits into
mainfrom
refactor-image-copy
Oct 22, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
refactor-image-copy

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​118 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5

Problem

Image copying logic lived inside native chat, making it harder to reuse and leaving preview coverage incomplete.

Solution

Move image conversion and clipboard writing into a shared utility. Native chat now uses it, and tests cover copying from both thumbnails and image previews.

ELI5

Copying an image now uses one shared path, so it works the same whether the image is shown small or opened in a preview.

What Changed

  • Added copyImageToClipboard to convert an image to PNG and write it to the local clipboard.
  • Updated native chat image copying to use the shared utility.
  • Added utility tests for successful copies and source, decode, and clipboard-write failures.
  • Extended native chat context-menu coverage to thumbnail and preview surfaces.

Why

A single copy path avoids duplicated conversion and clipboard logic while ensuring images copied from previews behave like images copied from thumbnails.

Linked Issue

If you do not have one and are an outside contributors, your PR wiil be ignored. Refs is not sufficient. Link an actual issue

Fixes # TODO

Visual Proof

N/A — no visual or interaction design change; this refactors clipboard handling and adds automated coverage.

Testing

  • Added/updated Vitest coverage for the shared clipboard utility and native chat thumbnail/preview copy flows.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d8bd0f68-0c57-445a-be6b-dc0250285b25
📥 Commits

Reviewing files that changed from the base of the PR and between 9620713 and 179ddc2.

📒 Files selected for processing: 4
  • src/renderer/src/components/native-chat/NativeChatResolvedView.context-menu.test.tsx
  • src/renderer/src/components/native-chat/native-chat-image-copy.ts
  • src/renderer/src/lib/clipboard-image-copy.test.ts
  • src/renderer/src/lib/clipboard-image-copy.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The change adds a shared helper that converts an image blob to PNG and writes it to the clipboard as a data URL. Native chat image copying now uses this helper. Tests cover helper success and error cases, pending writes, and copying from thumbnail and preview surfaces.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 179dd

Native-chat image copying retains its clipboard payload format, and no actionable issue remains before merge.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the problem, solution, changes, rationale, testing, and visual-proof status. However, the required Linked Issue section still contains the placeholder "Fixes # TODO", and seve… Replace "Fixes # TODO" with a valid linked issue. Complete or explicitly address the self-review, cross-platform impact, and lint, typecheck, test, and build validation items.
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: extracting a shared image clipboard copy utility.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, solution, changes, rationale, testing, and visual-proof status. However, the required Linked Issue section still contains the placeholder "Fixes # TODO", and several review and validation checklist items remain incomplete.

Resolution

Replace "Fixes # TODO" with a valid linked issue. Complete or explicitly address the self-review, cross-platform impact, and lint, typecheck, test, and build validation items.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang
AmethystLiang merged commit 718fb9f into main Oct 22, 2026
33 checks passed
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.

1 participant