diff --git a/models/user/setting_keys.go b/models/user/setting_keys.go index 10255735b3177..2f2c49a9d41c6 100644 --- a/models/user/setting_keys.go +++ b/models/user/setting_keys.go @@ -8,6 +8,8 @@ const ( SettingsKeyHiddenCommentTypes = "issue.hidden_comment_types" // SettingsKeyDiffWhitespaceBehavior is the setting key for whitespace behavior of diff SettingsKeyDiffWhitespaceBehavior = "diff.whitespace_behaviour" + // DiffViewWidth to set the size of the diff view + SettingsKeyDiffViewWidth = "diff.view_width" // UserActivityPubPrivPem is user's private key UserActivityPubPrivPem = "activitypub.priv_pem" // UserActivityPubPubPem is user's public key diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f784b10c8db4c..77202b276ea3f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2222,6 +2222,8 @@ diff.download_patch = Download Patch File diff.download_diff = Download Diff File diff.show_split_view = Split View diff.show_unified_view = Unified View +diff.show_full_width = Full Width +diff.show_compact_width = Compact Width diff.whitespace_button = Whitespace diff.whitespace_show_everything = Show all changes diff.whitespace_ignore_all_whitespace = Ignore whitespace when comparing lines diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go index 9a4aa3382cbba..81859c616de4b 100644 --- a/routers/web/repo/middlewares.go +++ b/routers/web/repo/middlewares.go @@ -60,6 +60,29 @@ func SetDiffViewStyle(ctx *context.Context) { } } +// SetDiffViewWidth set the width of the diff view +func SetDiffViewWidth(ctx *context.Context) { + const defaultViewWidthBehavior = "full" + viewWidthBehavior := ctx.FormString("width") + + if ctx.IsSigned { + userViewWidthBehavior, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyDiffViewWidth, defaultViewWidthBehavior) + if err == nil { + if viewWidthBehavior == "" { + viewWidthBehavior = userViewWidthBehavior + } else if viewWidthBehavior != userViewWidthBehavior { + _ = user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyDiffViewWidth, viewWidthBehavior) + } + } // else: we can ignore the error safely + } + + if viewWidthBehavior == "" { + ctx.Data["IsWidthFull"] = defaultViewWidthBehavior == "full" + } else { + ctx.Data["IsWidthFull"] = viewWidthBehavior == "full" + } +} + // SetWhitespaceBehavior set whitespace behavior as render variable func SetWhitespaceBehavior(ctx *context.Context) { const defaultWhitespaceBehavior = "show-all" diff --git a/routers/web/web.go b/routers/web/web.go index 88e27ad678992..32105f8cd8dde 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1044,9 +1044,9 @@ func RegisterRoutes(m *web.Route) { m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.TreeList) m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList) }) - m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff) + m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetDiffViewWidth, repo.SetWhitespaceBehavior, repo.CompareDiff) m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists). - Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff). + Get(ignSignIn, repo.SetDiffViewStyle, repo.SetDiffViewWidth, repo.SetWhitespaceBehavior, repo.CompareDiff). Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, web.Bind(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost) m.Group("/{type:issues|pulls}", func() { m.Group("/{index}", func() { @@ -1304,7 +1304,7 @@ func RegisterRoutes(m *web.Route) { reqRepoWikiWriter, web.Bind(forms.NewWikiForm{}), repo.WikiPost) - m.Get("/commit/{sha:[a-f0-9]{7,40}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) + m.Get("/commit/{sha:[a-f0-9]{7,40}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetDiffViewWidth, repo.SetWhitespaceBehavior, repo.Diff) m.Get("/commit/{sha:[a-f0-9]{7,40}}.{ext:patch|diff}", repo.RawDiff) }, repo.MustEnableWiki, func(ctx *context.Context) { ctx.Data["PageIsWiki"] = true @@ -1335,7 +1335,7 @@ func RegisterRoutes(m *web.Route) { }, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader) m.Group("/blob_excerpt", func() { - m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob) + m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetDiffViewWidth, repo.ExcerptBlob) }, func(ctx *context.Context) (cancel gocontext.CancelFunc) { if ctx.FormBool("wiki") { ctx.Data["PageIsWiki"] = true @@ -1366,7 +1366,7 @@ func RegisterRoutes(m *web.Route) { m.Post("/set_allow_maintainer_edit", web.Bind(forms.UpdateAllowEditsForm{}), repo.SetAllowEdits) m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest) m.Group("/files", func() { - m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.ViewPullFiles) + m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetDiffViewWidth, repo.SetWhitespaceBehavior, repo.ViewPullFiles) m.Group("/reviews", func() { m.Get("/new_comment", repo.RenderNewCodeCommentForm) m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.CreateCodeComment) @@ -1416,7 +1416,7 @@ func RegisterRoutes(m *web.Route) { m.Group("", func() { m.Get("/graph", repo.Graph) - m.Get("/commit/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) + m.Get("/commit/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetDiffViewWidth, repo.SetWhitespaceBehavior, repo.Diff) m.Get("/cherry-pick/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.CherryPick) }, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader) diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index b847a282bdd6b..9915b38dd0652 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -1,7 +1,7 @@ {{template "base/head" .}}
{{template "repo/header" .}} -
+
{{$class := ""}} {{if .Commit.Signature}} {{$class = (printf "%s%s" $class " isSigned")}} diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 1010863b799d7..cbaa024e7fce6 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -1,7 +1,7 @@ {{template "base/head" .}}
{{template "repo/header" .}} -
+

{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}} diff --git a/templates/repo/diff/whitespace_dropdown.tmpl b/templates/repo/diff/whitespace_dropdown.tmpl index 47a5ab5533c34..bcd1998287458 100644 --- a/templates/repo/diff/whitespace_dropdown.tmpl +++ b/templates/repo/diff/whitespace_dropdown.tmpl @@ -29,3 +29,4 @@

{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}} +{{if .IsWidthFull}}{{svg "gitea-lock"}}{{else}}{{svg "gitea-unlock"}}{{end}} diff --git a/templates/repo/pulls/files.tmpl b/templates/repo/pulls/files.tmpl index e5e91bf5c33f9..115a7786aa4f0 100644 --- a/templates/repo/pulls/files.tmpl +++ b/templates/repo/pulls/files.tmpl @@ -5,7 +5,7 @@
{{template "repo/header" .}} -
+