feat: add copy file contents button to code preview top bar#1724
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
📝 WalkthroughWalkthroughThis pull request modifies the package code viewer component to add clipboard functionality for copying file contents. A new clipboard instance and copied state are introduced to track the copy operation. A button is added to the UI that triggers the file content copy action when a file is being viewed. The button displays dynamic messaging and icons to reflect whether the content has been copied, utilising a 2000 millisecond feedback window consistent with the existing copy permalink functionality. The implementation adds 17 lines of code with no modifications to exported or public API signatures. Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue (1)
482-493: Minor consistency tweaks for the copy button.The implementation is functional. A few small suggestions for consistency:
- Icon choice: Consider using
i-lucide:copyori-lucide:clipboardinstead ofi-lucide:file— these more clearly convey a "copy" action.- Styling consistency: The adjacent "Copy link" button (line 477) has
active:scale-95for press feedback, but this button omits it. Thecapitalizeclass is also unique to this button.- Simplify condition:
v-if="fileContent?.content"suffices; the!!coercion is unnecessary sincev-ifalready evaluates truthiness.♻️ Optional: align styling with adjacent button
<button - v-if="!!fileContent?.content" + v-if="fileContent?.content" type="button" - class="px-2 py-1 font-mono text-xs text-fg-muted bg-bg-subtle border border-border rounded hover:text-fg hover:border-border-hover transition-colors inline-flex items-center gap-1 capitalize" + class="px-2 py-1 font-mono text-xs text-fg-muted bg-bg-subtle border border-border rounded hover:text-fg hover:border-border-hover transition-colors inline-flex items-center gap-1 active:scale-95" `@click`="copyFileContent()" > <span class="w-3 h-3" - :class="fileContentCopied ? 'i-lucide:check' : 'i-lucide:file'" + :class="fileContentCopied ? 'i-lucide:check' : 'i-lucide:copy'" /> {{ fileContentCopied ? $t('common.copied') : $t('common.copy') }} </button>Based on learnings, the inline copy button pattern is acceptable to keep inline rather than extract to a reusable component.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🔗 Linked issue
resolves #1690
🧭 Context
Added a copy/copied button that uses existing patterns and translation strings to copy currently viewed file contents to clipboard.