From efc48c36ff565d6333cc6894bd75b8be2259754e Mon Sep 17 00:00:00 2001 From: Aleksandr Denisovich <66480963+saneks222@users.noreply.github.com> Date: Thu, 2 Oct 2025 23:08:11 +0500 Subject: [PATCH] Added button to copy file name in PR files (#35509) The merge request file viewer has a button for copying the file path, but it is not always convenient. Often, you only want to copy the file name, which is currently not possible. This change request adds this capability. --------- Signed-off-by: wxiaoguang Co-authored-by: a.kiselev Co-authored-by: wxiaoguang --- options/locale/locale_en-US.ini | 1 + services/gitdiff/gitdiff.go | 9 +++++++++ templates/repo/diff/box.tmpl | 1 + 3 files changed, 11 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b3eb7b1f4a..64bc3b1871 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -109,6 +109,7 @@ copy_path = Copy path copy_success = Copied! copy_error = Copy failed copy_type_unsupported = This file type cannot be copied +copy_filename = Copy filename write = Write preview = Preview diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 1cc5ce66f8..2de87f9979 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -13,6 +13,7 @@ import ( "html/template" "io" "net/url" + "path" "sort" "strings" "time" @@ -403,6 +404,14 @@ func (diffFile *DiffFile) GetDiffFileName() string { return diffFile.Name } +// GetDiffFileBaseName returns the short name of the diff file, or its short old name in case it was deleted +func (diffFile *DiffFile) GetDiffFileBaseName() string { + if diffFile.Name == "" { + return path.Base(diffFile.OldName) + } + return path.Base(diffFile.Name) +} + func (diffFile *DiffFile) ShouldBeHidden() bool { return diffFile.IsGenerated || diffFile.IsViewed } diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index e4d1efac57..7eb96e1ddc 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -143,6 +143,7 @@ {{end}} + {{if not $.PageIsWiki}} {{if $file.IsDeleted}} {{ctx.Locale.Tr "repo.diff.view_file"}}