aboutsummaryrefslogtreecommitdiffstats
path: root/models/git_diff.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-06-24 21:23:52 +0100
committerGitHub <noreply@github.com>2019-06-24 21:23:52 +0100
commit5908bb103003912bd0ba3cefa66f2ff815ee8d8e (patch)
treeec0f4ff99314aa4e38334b436e1aea287b27cb7b /models/git_diff.go
parente07ff2f89064db8fa5c78a2a27a69d93183d10a4 (diff)
downloadgitea-5908bb103003912bd0ba3cefa66f2ff815ee8d8e.tar.gz
gitea-5908bb103003912bd0ba3cefa66f2ff815ee8d8e.zip
Make diff line-marker non-selectable (#7279)
* Make diff line-marker non-selectable * Move to use data-* as per @mrsdizzie * fix missing line nums * Add a minimum-width to force right-align of the line num * Move line-type-marker into separate column
Diffstat (limited to 'models/git_diff.go')
-rw-r--r--models/git_diff.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index a6ea7306d4..29c424c11c 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -80,6 +80,14 @@ func (d *DiffLine) GetCommentSide() string {
return d.Comments[0].DiffSide()
}
+// GetLineTypeMarker returns the line type marker
+func (d *DiffLine) GetLineTypeMarker() string {
+ if strings.IndexByte(" +-", d.Content[0]) > -1 {
+ return d.Content[0:1]
+ }
+ return ""
+}
+
// DiffSection represents a section of a DiffFile.
type DiffSection struct {
Name string
@@ -87,22 +95,14 @@ type DiffSection struct {
}
var (
- addedCodePrefix = []byte("<span class=\"added-code\">")
- removedCodePrefix = []byte("<span class=\"removed-code\">")
- codeTagSuffix = []byte("</span>")
+ addedCodePrefix = []byte(`<span class="added-code">`)
+ removedCodePrefix = []byte(`<span class="removed-code">`)
+ codeTagSuffix = []byte(`</span>`)
)
func diffToHTML(diffs []diffmatchpatch.Diff, lineType DiffLineType) template.HTML {
buf := bytes.NewBuffer(nil)
- // Reproduce signs which are cut for inline diff before.
- switch lineType {
- case DiffLineAdd:
- buf.WriteByte('+')
- case DiffLineDel:
- buf.WriteByte('-')
- }
-
for i := range diffs {
switch {
case diffs[i].Type == diffmatchpatch.DiffInsert && lineType == DiffLineAdd:
@@ -186,18 +186,21 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem
case DiffLineAdd:
compareDiffLine = diffSection.GetLine(DiffLineDel, diffLine.RightIdx)
if compareDiffLine == nil {
- return template.HTML(html.EscapeString(diffLine.Content))
+ return template.HTML(html.EscapeString(diffLine.Content[1:]))
}
diff1 = compareDiffLine.Content
diff2 = diffLine.Content
case DiffLineDel:
compareDiffLine = diffSection.GetLine(DiffLineAdd, diffLine.LeftIdx)
if compareDiffLine == nil {
- return template.HTML(html.EscapeString(diffLine.Content))
+ return template.HTML(html.EscapeString(diffLine.Content[1:]))
}
diff1 = diffLine.Content
diff2 = compareDiffLine.Content
default:
+ if strings.IndexByte(" +-", diffLine.Content[0]) > -1 {
+ return template.HTML(html.EscapeString(diffLine.Content[1:]))
+ }
return template.HTML(html.EscapeString(diffLine.Content))
}