feat: phase 1 changes: add comments feat to unchanged lines in the pull request.

This commit is contained in:
Rajesh Jonnalagadda 2024-11-11 07:03:55 +05:30
parent 0f397ae09b
commit 274ed54484
8 changed files with 292 additions and 82 deletions

View File

@ -14,6 +14,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
@ -39,6 +40,7 @@ import (
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/context/upload" "code.gitea.io/gitea/services/context/upload"
"code.gitea.io/gitea/services/gitdiff" "code.gitea.io/gitea/services/gitdiff"
user_service "code.gitea.io/gitea/services/user"
) )
const ( const (
@ -864,6 +866,14 @@ func ExcerptBlob(ctx *context.Context) {
direction := ctx.FormString("direction") direction := ctx.FormString("direction")
filePath := ctx.FormString("path") filePath := ctx.FormString("path")
gitRepo := ctx.Repo.GitRepo gitRepo := ctx.Repo.GitRepo
lastRightCommentIdx := ctx.FormInt("last_left_comment_idx")
rightCommentIdx := ctx.FormInt("left_comment_idx")
fileName := ctx.FormString("file_name")
if ctx.FormBool("pull") {
ctx.Data["PageIsPullFiles"] = true
}
if ctx.FormBool("wiki") { if ctx.FormBool("wiki") {
var err error var err error
gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
@ -873,6 +883,17 @@ func ExcerptBlob(ctx *context.Context) {
} }
defer gitRepo.Close() defer gitRepo.Close()
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
if err != nil {
ctx.ServerError("GetIssueByIndex", err)
return
}
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
lineCommits := allComments[fileName]
chunkSize := gitdiff.BlobExcerptChunkSize chunkSize := gitdiff.BlobExcerptChunkSize
commit, err := gitRepo.GetCommit(commitID) commit, err := gitRepo.GetCommit(commitID)
if err != nil { if err != nil {
@ -882,15 +903,16 @@ func ExcerptBlob(ctx *context.Context) {
section := &gitdiff.DiffSection{ section := &gitdiff.DiffSection{
FileName: filePath, FileName: filePath,
Name: filePath, Name: filePath,
Lines: []*gitdiff.DiffLine{},
} }
if direction == "up" && (idxLeft-lastLeft) > chunkSize { if direction == "up" && (idxLeft-lastLeft) > chunkSize {
idxLeft -= chunkSize idxLeft -= chunkSize
idxRight -= chunkSize idxRight -= chunkSize
leftHunkSize += chunkSize leftHunkSize += chunkSize
rightHunkSize += chunkSize rightHunkSize += chunkSize
section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize) section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize, lastRightCommentIdx, rightCommentIdx)
} else if direction == "down" && (idxLeft-lastLeft) > chunkSize { } else if direction == "down" && (idxLeft-lastLeft) > chunkSize {
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize) section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize, lastRightCommentIdx, rightCommentIdx)
lastLeft += chunkSize lastLeft += chunkSize
lastRight += chunkSize lastRight += chunkSize
} else { } else {
@ -898,7 +920,7 @@ func ExcerptBlob(ctx *context.Context) {
if direction == "down" { if direction == "down" {
offset = 0 offset = 0
} }
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset) section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset, lastRightCommentIdx, rightCommentIdx)
leftHunkSize = 0 leftHunkSize = 0
rightHunkSize = 0 rightHunkSize = 0
idxLeft = lastLeft idxLeft = lastLeft
@ -918,14 +940,18 @@ func ExcerptBlob(ctx *context.Context) {
Type: gitdiff.DiffLineSection, Type: gitdiff.DiffLineSection,
Content: lineText, Content: lineText,
SectionInfo: &gitdiff.DiffLineSectionInfo{ SectionInfo: &gitdiff.DiffLineSectionInfo{
Path: filePath, Path: filePath,
LastLeftIdx: lastLeft, LastLeftIdx: lastLeft,
LastRightIdx: lastRight, LastRightIdx: lastRight,
LeftIdx: idxLeft, LeftIdx: idxLeft,
RightIdx: idxRight, RightIdx: idxRight,
LeftHunkSize: leftHunkSize, LeftHunkSize: leftHunkSize,
RightHunkSize: rightHunkSize, RightHunkSize: rightHunkSize,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
}, },
Comments: nil,
} }
if direction == "up" { if direction == "up" {
section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...) section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...)
@ -933,14 +959,74 @@ func ExcerptBlob(ctx *context.Context) {
section.Lines = append(section.Lines, lineSection) section.Lines = append(section.Lines, lineSection)
} }
} }
for _, line := range section.Lines {
if line.SectionInfo != nil {
//for now considerign only right side.
start := int64(line.SectionInfo.LastRightIdx + 1)
end := int64(line.SectionInfo.RightIdx - 1)
//to check section has comments or not.
//1. we can use binary search
//2. we can LastRightCommentIdx, RightCommentIdx, LastLeftCommentIdx, LeftCommentIdx(little complex but fast)
//3. for demo using linear search
for start <= end {
if _, ok := lineCommits[start]; ok {
if !line.SectionInfo.HasComments {
// line.SectionInfo.LastRightCommentIdx = int(start)
// line.SectionInfo.RightCommentIdx = int(start)
line.SectionInfo.HasComments = true
break
}
}
start += 1
}
}
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
line.Comments = append(line.Comments, comments...)
}
if comments, ok := lineCommits[int64(line.RightIdx)]; ok {
line.Comments = append(line.Comments, comments...)
}
sort.SliceStable(line.Comments, func(i, j int) bool {
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
})
}
for _, line := range section.Lines {
for _, comment := range line.Comments {
if err := comment.LoadAttachments(ctx); err != nil {
ctx.ServerError("LoadAttachments", err)
return
}
}
}
ctx.Data["section"] = section ctx.Data["section"] = section
ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath) ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
ctx.Data["AfterCommitID"] = commitID ctx.Data["AfterCommitID"] = commitID
ctx.Data["Anchor"] = anchor ctx.Data["Anchor"] = anchor
ctx.Data["Issue"] = issue
ctx.Data["issue"] = issue.Index
ctx.Data["SignedUserID"] = ctx.Data["SignedUserID"]
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
}
if ctx.Data["SignedUserID"] == nil {
ctx.Data["SignedUserID"] = ctx.Doer.ID
}
ctx.Data["SignedUser"] = ctx.Doer
ctx.Data["IsSigned"] = ctx.Doer != nil
ctx.Data["Repository"] = ctx.Repo.Repository
ctx.Data["Permission"] = &ctx.Repo.Permission
ctx.HTML(http.StatusOK, tplBlobExcerpt) ctx.HTML(http.StatusOK, tplBlobExcerpt)
} }
func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize int) ([]*gitdiff.DiffLine, error) { func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize, lastRightCommentIdx, rightCommentIdx int) ([]*gitdiff.DiffLine, error) {
blob, err := commit.Tree.GetBlobByPath(filePath) blob, err := commit.Tree.GetBlobByPath(filePath)
if err != nil { if err != nil {
return nil, err return nil, err
@ -965,7 +1051,12 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
RightIdx: line + 1, RightIdx: line + 1,
Type: gitdiff.DiffLinePlain, Type: gitdiff.DiffLinePlain,
Content: " " + lineText, Content: " " + lineText,
Comments: []*issues_model.Comment{},
} }
// if diffLine.SectionInfo != nil {
// diffLine.SectionInfo.LastRightCommentIdx = lastRightCommentIdx
// diffLine.SectionInfo.RightCommentIdx = rightCommentIdx
// }
diffLines = append(diffLines, diffLine) diffLines = append(diffLines, diffLine)
} }
if err = scanner.Err(); err != nil { if err = scanner.Err(); err != nil {

View File

@ -1511,6 +1511,11 @@ func registerRoutes(m *web.Router) {
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob) m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
}, func(ctx *context.Context) gocontext.CancelFunc { }, func(ctx *context.Context) gocontext.CancelFunc {
// FIXME: refactor this function, use separate routes for wiki/code // FIXME: refactor this function, use separate routes for wiki/code
if ctx.FormBool("pull") {
ctx.Data["PageIsPullFiles"] = true
}
if ctx.FormBool("wiki") { if ctx.FormBool("wiki") {
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
repo.MustEnableWiki(ctx) repo.MustEnableWiki(ctx)

View File

@ -86,13 +86,16 @@ type DiffLine struct {
// DiffLineSectionInfo represents diff line section meta data // DiffLineSectionInfo represents diff line section meta data
type DiffLineSectionInfo struct { type DiffLineSectionInfo struct {
Path string Path string
LastLeftIdx int LastLeftIdx int
LastRightIdx int LastRightIdx int
LeftIdx int LeftIdx int
RightIdx int RightIdx int
LeftHunkSize int LeftHunkSize int
RightHunkSize int RightHunkSize int
HasComments bool
LastRightCommentIdx int
RightCommentIdx int
} }
// BlobExcerptChunkSize represent max lines of excerpt // BlobExcerptChunkSize represent max lines of excerpt
@ -118,7 +121,7 @@ func (d *DiffLine) GetHTMLDiffLineType() string {
// CanComment returns whether a line can get commented // CanComment returns whether a line can get commented
func (d *DiffLine) CanComment() bool { func (d *DiffLine) CanComment() bool {
return len(d.Comments) == 0 && d.Type != DiffLineSection return len(d.Comments) == 0
} }
// GetCommentSide returns the comment side of the first comment, if not set returns empty string // GetCommentSide returns the comment side of the first comment, if not set returns empty string
@ -143,10 +146,12 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
"last_left=%d&last_right=%d&"+ "last_left=%d&last_right=%d&"+
"left=%d&right=%d&"+ "left=%d&right=%d&"+
"left_hunk_size=%d&right_hunk_size=%d&"+ "left_hunk_size=%d&right_hunk_size=%d&"+
"last_rightt_comment_idx=%d&right_comment_idx=%d&"+
"path=%s", "path=%s",
d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx, d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx, d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize, d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
d.SectionInfo.LastRightCommentIdx, d.SectionInfo.RightCommentIdx,
url.QueryEscape(d.SectionInfo.Path)) url.QueryEscape(d.SectionInfo.Path))
return query return query
} }
@ -170,13 +175,16 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line) leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)
return &DiffLineSectionInfo{ return &DiffLineSectionInfo{
Path: treePath, Path: treePath,
LastLeftIdx: lastLeftIdx, LastLeftIdx: lastLeftIdx,
LastRightIdx: lastRightIdx, LastRightIdx: lastRightIdx,
LeftIdx: leftLine, LeftIdx: leftLine,
RightIdx: rightLine, RightIdx: rightLine,
LeftHunkSize: leftHunk, LeftHunkSize: leftHunk,
RightHunkSize: righHunk, RightHunkSize: righHunk,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
} }
} }
@ -396,11 +404,14 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommit, ri
Type: DiffLineSection, Type: DiffLineSection,
Content: " ", Content: " ",
SectionInfo: &DiffLineSectionInfo{ SectionInfo: &DiffLineSectionInfo{
Path: diffFile.Name, Path: diffFile.Name,
LastLeftIdx: lastLine.LeftIdx, LastLeftIdx: lastLine.LeftIdx,
LastRightIdx: lastLine.RightIdx, LastRightIdx: lastLine.RightIdx,
LeftIdx: leftLineCount, LeftIdx: leftLineCount,
RightIdx: rightLineCount, RightIdx: rightLineCount,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
}, },
} }
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}} tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
@ -458,16 +469,38 @@ type Diff struct {
NumViewedFiles int // user-specific NumViewedFiles int // user-specific
} }
// function (section *DiffSection) GetType() int {
// LoadComments loads comments into each line // LoadComments loads comments into each line
func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error { func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error {
allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments) allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments)
if err != nil { if err != nil {
return err return err
} }
for _, file := range diff.Files { for _, file := range diff.Files {
if lineCommits, ok := allComments[file.Name]; ok { if lineCommits, ok := allComments[file.Name]; ok {
for _, section := range file.Sections { for _, section := range file.Sections {
for _, line := range section.Lines { for _, line := range section.Lines {
if line.SectionInfo != nil {
start := int64(line.SectionInfo.LastRightIdx + 1)
end := int64(line.SectionInfo.RightIdx - 1)
for start <= end {
if _, ok := lineCommits[start]; ok {
if line.SectionInfo.LastRightCommentIdx == 0 {
// line.SectionInfo.LastRightCommentIdx = int(start)
// line.SectionInfo.RightCommentIdx = int(start)
line.SectionInfo.HasComments = true
break
}
}
start += 1
}
}
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok { if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
line.Comments = append(line.Comments, comments...) line.Comments = append(line.Comments, comments...)
} }

View File

@ -59,13 +59,16 @@ func TestGetDiffPreview(t *testing.T) {
Content: "@@ -1,3 +1,4 @@", Content: "@@ -1,3 +1,4 @@",
Comments: nil, Comments: nil,
SectionInfo: &gitdiff.DiffLineSectionInfo{ SectionInfo: &gitdiff.DiffLineSectionInfo{
Path: "README.md", Path: "README.md",
LastLeftIdx: 0, LastLeftIdx: 0,
LastRightIdx: 0, LastRightIdx: 0,
LeftIdx: 1, LeftIdx: 1,
RightIdx: 1, RightIdx: 1,
LeftHunkSize: 3, LeftHunkSize: 3,
RightHunkSize: 4, RightHunkSize: 4,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
}, },
}, },
{ {

View File

@ -1,35 +1,49 @@
{{if $.IsSplitStyle}} {{if $.IsSplitStyle}}
{{range $k, $line := $.section.Lines}} {{range $k, $line := $.section.Lines}}
{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
<tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}} line-expanded"> <tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}} line-expanded">
{{if eq .GetType 4}} {{if eq .GetType 4}}
{{$expandDirection := $line.GetExpandDirection}} {{$expandDirection := $line.GetExpandDirection}}
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"> <td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}">
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}"> <div class="lines-comment">
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} <div>
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}"> {{if $line.SectionInfo.HasComments}}
{{svg "octicon-fold-down"}} <button>
</button> {{svg "octicon-comment-discussion"}}
{{end}} </button>
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{end}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}"> </div>
{{svg "octicon-fold-up"}} <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
</button> {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
{{end}} <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
{{if eq $expandDirection 2}} {{svg "octicon-fold-down"}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}"> </button>
{{svg "octicon-fold"}} {{end}}
</button> {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
{{end}} <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
</div> {{svg "octicon-fold-up"}}
</td> </button>
{{end}}
{{if eq $expandDirection 2}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
{{svg "octicon-fold"}}
</button>
{{end}}
</div>
</div>
</td>
<td colspan="7" class="lines-code lines-code-old ">{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}{{/* <td colspan="7" class="lines-code lines-code-old ">{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}{{/*
*/}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}</td> */}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}</td>
{{else}} {{else}}
{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td> <td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
<td class="lines-escape lines-escape-old">{{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td> <td class="lines-escape lines-escape-old">{{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td> <td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td>
<td class="lines-code lines-code-old">{{/* <td class="lines-code lines-code-old">{{/*
*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
*/}}<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
*/}}{{svg "octicon-plus"}}{{/*
*/}}</button>{{/*
*/}}{{end}}{{/*
*/}}{{if $line.LeftIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/* */}}{{if $line.LeftIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/*
*/}}<code class="code-inner"></code>{{/* */}}<code class="code-inner"></code>{{/*
*/}}{{end}}{{/* */}}{{end}}{{/*
@ -38,45 +52,81 @@
<td class="lines-escape lines-escape-new">{{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td> <td class="lines-escape lines-escape-new">{{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td> <td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td>
<td class="lines-code lines-code-new">{{/* <td class="lines-code lines-code-new">{{/*
*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
*/}}<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
*/}}{{svg "octicon-plus"}}{{/*
*/}}</button>{{/*
*/}}{{end}}{{/*
*/}}{{if $line.RightIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/* */}}{{if $line.RightIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/*
*/}}<code class="code-inner"></code>{{/* */}}<code class="code-inner"></code>{{/*
*/}}{{end}}{{/* */}}{{end}}{{/*
*/}}</td> */}}</td>
{{end}} {{end}}
</tr> </tr>
{{if $line.Comments}}
<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
<td class="add-comment-right" colspan="5">
{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}}
</td>
</tr>
{{end}}
{{end}} {{end}}
{{else}} {{else}}
{{range $k, $line := $.section.Lines}} {{range $k, $line := $.section.Lines}}
{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
<tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}} line-expanded"> <tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}} line-expanded">
{{if eq .GetType 4}} {{if eq .GetType 4}}
{{$expandDirection := $line.GetExpandDirection}} {{$expandDirection := $line.GetExpandDirection}}
<td colspan="2" class="lines-num"> <td colspan="2" class="lines-num">
<div class="lines-comment">
<div>
{{if $line.SectionInfo.HasComments}}
<button>
{{svg "octicon-comment-discussion"}}
</button>
{{end}}
</div>
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}"> <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}"> <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
{{svg "octicon-fold-down"}} {{svg "octicon-fold-down"}}
</button> </button>
test else down blob {{$line.SectionInfo.HasComments}}
{{end}} {{end}}
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}"> <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
{{svg "octicon-fold-up"}} {{svg "octicon-fold-up"}}
</button> </button>
test else up blob
{{end}} {{end}}
{{if eq $expandDirection 2}} {{if eq $expandDirection 2}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}"> <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
{{svg "octicon-fold"}} {{svg "octicon-fold"}}
</button> </button>
test else both blob
{{end}} {{end}}
</div> </div>
</div>
</td> </td>
{{else}} {{else}}
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td> <td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{$.FileNameHash}}R{{$line.RightIdx}}{{end}}"></span></td> <td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{$.FileNameHash}}R{{$line.RightIdx}}{{end}}"></span></td>
{{end}} {{end}}
{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
<td class="lines-escape">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td> <td class="lines-escape">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
<td class="lines-type-marker"><span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td> <td class="lines-type-marker"><span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td>
<td class="lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}"><code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td> <td class="lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}">
{{if and $.SignedUserID $.PageIsPullFiles}}
<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{svg "octicon-plus"}}
</button>
{{end}}
<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>
</tr> </tr>
{{if $line.Comments}}
<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
<td class="add-comment-right" colspan="5">
{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}
</td>
</tr>
{{end}}
{{end}} {{end}}
{{end}} {{end}}

View File

@ -18,22 +18,31 @@
{{if eq .GetType 4}} {{if eq .GetType 4}}
{{$expandDirection := $line.GetExpandDirection}} {{$expandDirection := $line.GetExpandDirection}}
<td class="lines-num lines-num-old"> <td class="lines-num lines-num-old">
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}"> <div class="lines-comment">
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} <div>
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> {{if $line.SectionInfo.HasComments}}
{{svg "octicon-fold-down"}} <button>
</button> {{svg "octicon-comment-discussion"}}
{{end}} </button>
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{end}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> </div>
{{svg "octicon-fold-up"}} <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
</button> {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
{{end}} <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
{{if eq $expandDirection 2}} {{svg "octicon-fold-down"}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> </button>
{{svg "octicon-fold"}} {{end}}
</button> {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
{{end}} <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
{{svg "octicon-fold-up"}}
</button>
{{end}}
{{if eq $expandDirection 2}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
{{svg "octicon-fold"}}
</button>
{{end}}
</div>
</div> </div>
</td>{{$inlineDiff := $section.GetComputedInlineDiffFor $line ctx.Locale}} </td>{{$inlineDiff := $section.GetComputedInlineDiffFor $line ctx.Locale}}
<td class="lines-escape lines-escape-old">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td> <td class="lines-escape lines-escape-old">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>

View File

@ -14,23 +14,35 @@
{{if $.root.AfterCommitID}} {{if $.root.AfterCommitID}}
{{$expandDirection := $line.GetExpandDirection}} {{$expandDirection := $line.GetExpandDirection}}
<td colspan="2" class="lines-num"> <td colspan="2" class="lines-num">
<div class="lines-comment">
<div>
{{if $line.SectionInfo.HasComments}}
<button>
{{svg "octicon-comment-discussion"}}
</button>
{{end}}
</div>
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}"> <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
{{svg "octicon-fold-down"}} {{svg "octicon-fold-down"}}
</button> </button>
test down
{{end}} {{end}}
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}} {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
{{svg "octicon-fold-up"}} {{svg "octicon-fold-up"}}
</button> </button>
test up
{{end}} {{end}}
{{if eq $expandDirection 2}} {{if eq $expandDirection 2}}
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
{{svg "octicon-fold"}} {{svg "octicon-fold"}}
</button> </button>
test fold
{{end}} {{end}}
</div> </div>
</div>
</td> </td>
{{else}} {{else}}
{{/* for code file preview page or comment diffs on pull comment pages, do not show the expansion arrows */}} {{/* for code file preview page or comment diffs on pull comment pages, do not show the expansion arrows */}}

View File

@ -1141,6 +1141,13 @@ overflow-menu .ui.label {
font-family: var(--fonts-regular); font-family: var(--fonts-regular);
} }
.lines-comment {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1px;
}
.lines-commit .blame-info .blame-data .blame-message { .lines-commit .blame-info .blame-data .blame-message {
flex-grow: 2; flex-grow: 2;
overflow: hidden; overflow: hidden;