Skip to content

Commit efc48c3

Browse files
saneks222a.kiselevwxiaoguang
authored
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 <[email protected]> Co-authored-by: a.kiselev <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 340aed3 commit efc48c3

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ copy_path = Copy path
109109
copy_success = Copied!
110110
copy_error = Copy failed
111111
copy_type_unsupported = This file type cannot be copied
112+
copy_filename = Copy filename
112113

113114
write = Write
114115
preview = Preview

services/gitdiff/gitdiff.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"html/template"
1414
"io"
1515
"net/url"
16+
"path"
1617
"sort"
1718
"strings"
1819
"time"
@@ -403,6 +404,14 @@ func (diffFile *DiffFile) GetDiffFileName() string {
403404
return diffFile.Name
404405
}
405406

407+
// GetDiffFileBaseName returns the short name of the diff file, or its short old name in case it was deleted
408+
func (diffFile *DiffFile) GetDiffFileBaseName() string {
409+
if diffFile.Name == "" {
410+
return path.Base(diffFile.OldName)
411+
}
412+
return path.Base(diffFile.Name)
413+
}
414+
406415
func (diffFile *DiffFile) ShouldBeHidden() bool {
407416
return diffFile.IsGenerated || diffFile.IsViewed
408417
}

templates/repo/diff/box.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<button class="unescape-button item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
144144
<button class="escape-button tw-hidden item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
145145
{{end}}
146+
<button class="item" data-clipboard-text="{{$file.GetDiffFileBaseName}}">{{ctx.Locale.Tr "copy_filename"}}</button>
146147
{{if not $.PageIsWiki}}
147148
{{if $file.IsDeleted}}
148149
<a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>

0 commit comments

Comments
 (0)