Skip to content

Commit e94eea4

Browse files
author
a.kiselev
committed
Added button to copy file name to changed files browser pull request
1 parent 4730bb5 commit e94eea4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ copy_hash = Copy hash
106106
copy_content = Copy content
107107
copy_branch = Copy branch name
108108
copy_path = Copy path
109+
copy_name = Copy name
109110
copy_success = Copied!
110111
copy_error = Copy failed
111112
copy_type_unsupported = This file type cannot be copied

services/gitdiff/gitdiff.go

Lines changed: 11 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/filepath"
1617
"sort"
1718
"strings"
1819
"time"
@@ -312,6 +313,7 @@ type DiffFile struct {
312313

313314
// basic fields (parsed from diff result)
314315
Name string
316+
ShortName string
315317
NameHash string
316318
OldName string
317319
Addition int
@@ -401,6 +403,14 @@ func (diffFile *DiffFile) GetDiffFileName() string {
401403
return diffFile.Name
402404
}
403405

406+
// GetDiffFileName returns the short name of the diff file, or its short old name in case it was deleted
407+
func (diffFile *DiffFile) GetDiffFileShortName() string {
408+
if diffFile.Name == "" {
409+
return filepath.Base(diffFile.OldName)
410+
}
411+
return filepath.Base(diffFile.Name)
412+
}
413+
404414
func (diffFile *DiffFile) ShouldBeHidden() bool {
405415
return diffFile.IsGenerated || diffFile.IsViewed
406416
}
@@ -1027,6 +1037,7 @@ func createDiffFile(line string) *DiffFile {
10271037

10281038
curFile.OldName, oldNameAmbiguity = readFileName(rd)
10291039
curFile.Name, newNameAmbiguity = readFileName(rd)
1040+
curFile.ShortName = curFile.GetDiffFileShortName()
10301041
if oldNameAmbiguity && newNameAmbiguity {
10311042
curFile.isAmbiguous = true
10321043
// OK we should bet that the oldName and the newName are the same if they can be made to be same

templates/repo/diff/box.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
</div>
103103
<span class="file tw-flex tw-items-center tw-font-mono tw-flex-1"><a class="muted file-link" title="{{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}" href="#diff-{{$file.NameHash}}">{{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}</a>
104104
<button class="btn interact-fg tw-p-2" data-clipboard-text="{{$file.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_path"}}">{{svg "octicon-copy" 14}}</button>
105+
<button class="btn interact-fg tw-p-2" data-clipboard-text="{{$file.ShortName}}" data-tooltip-content="{{ctx.Locale.Tr "copy_name"}}">{{svg "octicon-file" 14}}</button>
105106
{{if .IsLFSFile}}<span class="ui label">LFS</span>{{end}}
106107
{{if $file.IsGenerated}}
107108
<span class="ui label">{{ctx.Locale.Tr "repo.diff.generated"}}</span>

0 commit comments

Comments
 (0)