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 <wxiaoguang@gmail.com>
Co-authored-by: a.kiselev <a.kiselev@reglab.ru>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Aleksandr Denisovich 2025-10-02 23:08:11 +05:00 committed by GitHub
parent 340aed3982
commit efc48c36ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -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
}

View File

@ -143,6 +143,7 @@
<button class="unescape-button item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
<button class="escape-button tw-hidden item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
{{end}}
<button class="item" data-clipboard-text="{{$file.GetDiffFileBaseName}}">{{ctx.Locale.Tr "copy_filename"}}</button>
{{if not $.PageIsWiki}}
{{if $file.IsDeleted}}
<a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>