appview/pages: add diff opts selector #325

merged
opened by oppi.li targeting master from push-qkpqsrknozxs
Changed files
+54 -16
appview
types
+4 -1
appview/pages/templates/repo/commit.html
···
{{end}}
{{ define "contentAfterLeft" }}
-
<div class="sticky top-0">
{{ template "repo/fragments/diffChangedFiles" .Diff }}
</div>
{{end}}
···
{{end}}
{{ define "contentAfterLeft" }}
+
<div class="flex flex-col gap-4 col-span-1 md:col-span-2 mt-4">
+
{{ template "repo/fragments/diffOpts" .DiffOpts }}
+
</div>
+
<div class="sticky top-0 mt-4">
{{ template "repo/fragments/diffChangedFiles" .Diff }}
</div>
{{end}}
+5 -2
appview/pages/templates/repo/compare/compare.html
···
{{end}}
{{ define "contentAfterLeft" }}
-
<div class="sticky top-0">
-
{{ template "repo/fragments/diffChangedFiles" .Diff }}
</div>
{{end}}
···
{{end}}
{{ define "contentAfterLeft" }}
+
<div class="flex flex-col gap-4 col-span-1 md:col-span-2 mt-4">
+
{{ template "repo/fragments/diffOpts" .DiffOpts }}
+
</div>
+
<div class="sticky top-0 mt-4">
+
{{ template "repo/fragments/diffChangedFiles" .Diff }}
</div>
{{end}}
+8 -10
appview/pages/templates/repo/fragments/diffChangedFiles.html
···
{{ define "repo/fragments/diffChangedFiles" }}
{{ $stat := .Stat }}
{{ $fileTree := fileTree .ChangedFiles }}
-
<div class="col-span-1 md:col-span-2 mt-4">
-
<section class="sticky top-0 overflow-x-auto text-sm px-6 py-2 border border-gray-200 dark:border-gray-700 w-full mx-auto md:min-h-screen rounded bg-white dark:bg-gray-800 drop-shadow-sm">
-
<div class="diff-stat">
-
<div class="flex gap-2 items-center">
-
<strong class="text-sm uppercase dark:text-gray-200">Changed files</strong>
-
{{ template "repo/fragments/diffStatPill" $stat }}
-
</div>
-
{{ template "repo/fragments/fileTree" $fileTree }}
</div>
-
</section>
-
</div>
{{ end }}
···
{{ define "repo/fragments/diffChangedFiles" }}
{{ $stat := .Stat }}
{{ $fileTree := fileTree .ChangedFiles }}
+
<section class="overflow-x-auto text-sm px-6 py-2 border border-gray-200 dark:border-gray-700 w-full mx-auto md:min-h-screen rounded bg-white dark:bg-gray-800 drop-shadow-sm">
+
<div class="diff-stat">
+
<div class="flex gap-2 items-center">
+
<strong class="text-sm uppercase dark:text-gray-200">Changed files</strong>
+
{{ template "repo/fragments/diffStatPill" $stat }}
</div>
+
{{ template "repo/fragments/fileTree" $fileTree }}
+
</div>
+
</section>
{{ end }}
+28
appview/pages/templates/repo/fragments/diffOpts.html
···
···
+
{{ define "repo/fragments/diffOpts" }}
+
<section class="flex flex-col gap-2 overflow-x-auto text-sm px-6 py-2 border border-gray-200 dark:border-gray-700 w-full mx-auto rounded bg-white dark:bg-gray-800 drop-shadow-sm">
+
<strong class="text-sm uppercase dark:text-gray-200">options</strong>
+
{{ $active := "unified" }}
+
{{ if .Split }}
+
{{ $active = "split" }}
+
{{ end }}
+
{{ $values := list "unified" "split" }}
+
{{ block "tabSelector" (dict "Name" "diff" "Values" $values "Active" $active) }} {{ end }}
+
</section>
+
{{ end }}
+
+
{{ define "tabSelector" }}
+
{{ $name := .Name }}
+
{{ $all := .Values }}
+
{{ $active := .Active }}
+
<div class="flex justify-between divide-x divide-gray-200 dark:divide-gray-700 rounded border border-gray-200 dark:border-gray-700 overflow-hidden">
+
{{ $activeTab := "bg-white dark:bg-gray-700 shadow-sm" }}
+
{{ $inactiveTab := "bg-gray-100 dark:bg-gray-800 shadow-inner" }}
+
{{ range $index, $value := $all }}
+
{{ $isActive := eq $value $active }}
+
<a href="?{{ $name }}={{ $value }}"
+
class="py-2 text-sm w-full block hover:no-underline text-center {{ if $isActive }} {{$activeTab }} {{ else }} {{ $inactiveTab }} {{ end }}">
+
{{ $value }}
+
</a>
+
{{ end }}
+
</div>
+
{{ end }}
+4 -1
appview/pages/templates/repo/pulls/interdiff.html
···
{{end}}
{{ define "contentAfterLeft" }}
-
<div class="sticky top-0">
{{ template "repo/fragments/interdiffFiles" .Interdiff }}
</div>
{{end}}
···
{{end}}
{{ define "contentAfterLeft" }}
+
<div class="flex flex-col gap-4 col-span-1 md:col-span-2 mt-4">
+
{{ template "repo/fragments/diffOpts" .DiffOpts }}
+
</div>
+
<div class="sticky top-0 mt-4">
{{ template "repo/fragments/interdiffFiles" .Interdiff }}
</div>
{{end}}
+4 -1
appview/pages/templates/repo/pulls/patch.html
···
{{end}}
{{ define "contentAfterLeft" }}
-
<div class="sticky top-0">
{{ template "repo/fragments/diffChangedFiles" .Diff }}
</div>
{{end}}
···
{{end}}
{{ define "contentAfterLeft" }}
+
<div class="flex flex-col gap-4 col-span-1 md:col-span-2 mt-4">
+
{{ template "repo/fragments/diffOpts" .DiffOpts }}
+
</div>
+
<div class="sticky top-0 mt-4">
{{ template "repo/fragments/diffChangedFiles" .Diff }}
</div>
{{end}}
+1 -1
types/split.go
···
lines := fragment.Lines
var leftLines, rightLines []SplitLine
oldLineNum := fragment.OldPosition
-
newLineNum := fragment.OldPosition
// process deletions and additions in groups for better alignment
i := 0
···
lines := fragment.Lines
var leftLines, rightLines []SplitLine
oldLineNum := fragment.OldPosition
+
newLineNum := fragment.NewPosition
// process deletions and additions in groups for better alignment
i := 0