diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 255a6698..51e339fa 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -527,6 +527,7 @@ type RepoCommitParams struct { Active string EmailToDidOrHandle map[string]string Pipeline *db.Pipeline + DiffOpts types.DiffOpts // singular because it's always going to be just one VerifiedCommit commitverify.VerifiedCommits @@ -859,6 +860,7 @@ type RepoPullPatchParams struct { Round int Submission *db.PullSubmission OrderedReactionKinds []db.ReactionKind + DiffOpts types.DiffOpts } // this name is a mouthful @@ -964,6 +966,7 @@ type RepoCompareParams struct { Base string Head string Diff *types.NiceDiff + DiffOpts types.DiffOpts Active string } diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html index 266b1bbf..e71bd1dc 100644 --- a/appview/pages/templates/repo/commit.html +++ b/appview/pages/templates/repo/commit.html @@ -119,7 +119,7 @@ {{ end }} {{ define "contentAfter" }} - {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff) }} + {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff .DiffOpts) }} {{end}} {{ define "contentAfterLeft" }} diff --git a/appview/pages/templates/repo/compare/compare.html b/appview/pages/templates/repo/compare/compare.html index 389912f9..08c23194 100644 --- a/appview/pages/templates/repo/compare/compare.html +++ b/appview/pages/templates/repo/compare/compare.html @@ -50,7 +50,7 @@ {{ end }} {{ define "contentAfter" }} - {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff) }} + {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff .DiffOpts) }} {{end}} {{ define "contentAfterLeft" }} diff --git a/appview/pages/templates/repo/fragments/diff.html b/appview/pages/templates/repo/fragments/diff.html index 65193463..2e79bb94 100644 --- a/appview/pages/templates/repo/fragments/diff.html +++ b/appview/pages/templates/repo/fragments/diff.html @@ -1,8 +1,11 @@ {{ define "repo/fragments/diff" }} {{ $repo := index . 0 }} {{ $diff := index . 1 }} +{{ $opts := index . 2 }} + {{ $commit := $diff.Commit }} {{ $diff := $diff.Diff }} +{{ $isSplit := $opts.Split }} {{ $this := $commit.This }} {{ $parent := $commit.Parent }} @@ -85,45 +88,11 @@ This is a binary file and will not be displayed.
{{ else }} - {{ $name := .Name.New }} -+ {{ if $isSplit }} + {{- template "repo/fragments/splitDiff" .Split -}} + {{ else }} + {{- template "repo/fragments/unifiedDiff" . -}} + {{ end }} {{- end -}} @@ -136,6 +105,115 @@ {{ end }} {{ end }} +{{ define "unifiedDiffLines" }} +{{ $name := .Name.New }} +{{- range .TextFragments -}}···- {{- $oldStart := .OldPosition -}} - {{- $newStart := .NewPosition -}} - {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800 scroll-mt-10 target:border target:border-amber-500 target:rounded " -}} - {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} - {{- $lineNrSepStyle1 := "" -}} - {{- $lineNrSepStyle2 := "pr-2" -}} - {{- range .Lines -}} - {{- if eq .Op.String "+" -}} - - {{- $newStart = add64 $newStart 1 -}} - {{- end -}} - {{- if eq .Op.String "-" -}} - - {{- $oldStart = add64 $oldStart 1 -}} - {{- end -}} - {{- if eq .Op.String " " -}} - - {{- $newStart = add64 $newStart 1 -}} - {{- $oldStart = add64 $oldStart 1 -}} - {{- end -}} - {{- end -}} - {{- end -}}
+{{ end }} + +{{ define "splitDiffLines" }} +{{ $name := .Name.New }} +{{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800" -}} +{{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} +{{- $lineNrSepStyle := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} +{{- $containerStyle := "flex min-w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} +{{- $emptyStyle := "bg-gray-200/30 dark:bg-gray-700/30" -}} +{{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400" -}} +{{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} +{{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} +{{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} +{{- range .TextFragments -}}···+ {{- $oldStart := .OldPosition -}} + {{- $newStart := .NewPosition -}} + {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800 target:bg-yellow-200 target:dark:bg-yellow-600" -}} + {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} + {{- $lineNrSepStyle1 := "" -}} + {{- $lineNrSepStyle2 := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} + {{- $containerStyle := "flex min-w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} + {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 " -}} + {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} + {{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} + {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} + {{- range .Lines -}} + {{- if eq .Op.String "+" -}} + + {{- $newStart = add64 $newStart 1 -}} + {{- end -}} + {{- if eq .Op.String "-" -}} + + {{- $oldStart = add64 $oldStart 1 -}} + {{- end -}} + {{- if eq .Op.String " " -}} + + {{- $newStart = add64 $newStart 1 -}} + {{- $oldStart = add64 $oldStart 1 -}} + {{- end -}} + {{- end -}} + {{- end -}}
+ +{{- range .TextFragments -}}···+ {{- range .LeftLines -}} + {{- if .IsEmpty -}} +++ {{- else if eq .Op.String "-" -}} + + {{- else if eq .Op.String " " -}} + + {{- end -}} + {{- end -}} + {{- end -}}++ +
+{{- range .TextFragments -}}···+ {{- range .RightLines -}} + {{- if .IsEmpty -}} +++ {{- else if eq .Op.String "+" -}} + + {{- else if eq .Op.String " " -}} + + {{- end -}} + {{- end -}} + {{- end -}}++ +