Skip to content

Commit 1299c71

Browse files
committed
feat: add copy file contents button to code preview top bar
1 parent 85ac3d7 commit 1299c71

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ function copyPermalinkUrl() {
249249
copyPermalink(url.toString())
250250
}
251251
252+
const { copied: fileContentCopied, copy: copyFileContent } = useClipboard({
253+
source: () => fileContent.value?.content || '',
254+
copiedDuring: 2000,
255+
})
256+
252257
// Scroll to top of file content
253258
const contentContainer = useTemplateRef('contentContainer')
254259
function scrollToTop() {
@@ -474,6 +479,18 @@ defineOgImageComponent('Default', {
474479
>
475480
{{ permalinkCopied ? $t('common.copied') : $t('code.copy_link') }}
476481
</button>
482+
<button
483+
v-if="!!fileContent?.content"
484+
type="button"
485+
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"
486+
@click="copyFileContent()"
487+
>
488+
<span
489+
class="w-3 h-3"
490+
:class="fileContentCopied ? 'i-lucide:check' : 'i-lucide:file'"
491+
/>
492+
{{ fileContentCopied ? $t('common.copied') : $t('common.copy') }}
493+
</button>
477494
<a
478495
:href="`https://cdn.jsdelivr.net/npm/${packageName}@${version}/${filePath}`"
479496
target="_blank"

0 commit comments

Comments
 (0)