From 512e495e01fe477c9ce319a04c34c10d0767d892 Mon Sep 17 00:00:00 2001 From: eti Date: Tue, 26 May 2026 15:42:42 +0200 Subject: [PATCH] appview/repo: copy file contents to clipboard this pull request adds a "copy to clipboard" button on both the readme of a repository and the file view shown when viewing a specific file Signed-off-by: eti --- appview/models/repo.go | 4 ++ appview/pages/templates/repo/blob.html | 8 +++- .../repo/fragments/copyFileButton.html | 9 +++++ .../repo/fragments/copyFileScript.html | 38 +++++++++++++++++++ .../templates/repo/fragments/readme.html | 6 ++- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 appview/pages/templates/repo/fragments/copyFileButton.html create mode 100644 appview/pages/templates/repo/fragments/copyFileScript.html diff --git a/appview/models/repo.go b/appview/models/repo.go index 02afc6f4..01ec43fb 100644 --- a/appview/models/repo.go +++ b/appview/models/repo.go @@ -236,3 +236,7 @@ func (b BlobView) IsUnsupported() bool { func (b BlobView) ShowingText() bool { return !b.ShowingRendered } + +func (b BlobView) ShowCopy() bool { + return b.ContentType.IsCode() || b.ContentType.IsMarkup() || b.ContentType.IsSvg() || b.ContentType.IsImage() +} diff --git a/appview/pages/templates/repo/blob.html b/appview/pages/templates/repo/blob.html index a3a5cdad..14ced910 100644 --- a/appview/pages/templates/repo/blob.html +++ b/appview/pages/templates/repo/blob.html @@ -48,6 +48,11 @@ View raw {{ end }} + {{ if .BlobView.ShowCopy }} + + {{ template "repo/fragments/copyFileButton" (dict "Url" (printf "/%s/raw/%s/%s" .RepoInfo.FullName (pathEscape .Ref) .Path)) }} + {{ end }} + {{ if .BlobView.ShowToggle }} @@ -58,7 +63,7 @@ {{ if .BlobView.ShowingText }}
-
{{ end }} {{ template "fragments/multiline-select" }} + {{ template "repo/fragments/copyFileScript" }} +{{ end }} diff --git a/appview/pages/templates/repo/fragments/readme.html b/appview/pages/templates/repo/fragments/readme.html index ee9e77f7..dcf99644 100644 --- a/appview/pages/templates/repo/fragments/readme.html +++ b/appview/pages/templates/repo/fragments/readme.html @@ -1,9 +1,12 @@ {{ define "repo/fragments/readme" }}
{{- if .ReadmeFileName -}} -
+
+ {{ i "file-text" "w-4 h-4" "text-gray-600 dark:text-gray-400" }} {{ .ReadmeFileName }} + + {{ template "repo/fragments/copyFileButton" (dict "Url" (printf "/%s/raw/%s/%s" .RepoInfo.FullName (pathEscape .Ref) .ReadmeFileName)) }}
{{- end -}}
+{{ template "repo/fragments/copyFileScript" }} {{ end }} -- 2.51.2