Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to change width of diff view #22824

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions models/user/setting_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions routers/web/repo/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion templates/repo/commit_page.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository diff">
{{template "repo/header" .}}
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
<div class="ui container {{if .IsWidthFull}}fluid padded{{end}}">
{{$class := ""}}
{{if .Commit.Signature}}
{{$class = (printf "%s%s" $class " isSigned")}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/compare.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
{{template "repo/header" .}}
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
<div class="ui container {{if .IsWidthFull}}fluid padded{{end}}">

<h2 class="ui header">
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}
Expand Down
1 change: 1 addition & 0 deletions templates/repo/diff/whitespace_dropdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
</div>
</div>
<a class="ui tiny basic toggle button icon-button tooltip" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}&whitespace={{$.WhitespaceBehavior}}" data-content="{{if .IsSplitStyle}}{{.locale.Tr "repo.diff.show_unified_view"}}{{else}}{{.locale.Tr "repo.diff.show_split_view"}}{{end}}">{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}}</a>
<a class="ui tiny basic toggle button icon-button tooltip" href="?width={{if .IsWidthFull}}compact{{else}}full{{end}}&whitespace={{$.WhitespaceBehavior}}" data-content="{{if .IsWidthFull}}{{.locale.Tr "repo.diff.show_compact_width"}}{{else}}{{.locale.Tr "repo.diff.show_full_width"}}{{end}}">{{if .IsWidthFull}}{{svg "gitea-lock"}}{{else}}{{svg "gitea-unlock"}}{{end}}</a>
2 changes: 1 addition & 1 deletion templates/repo/pulls/files.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div role="main" aria-label="{{.Title}}" class="page-content repository view issue pull files diff">
{{template "repo/header" .}}
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
<div class="ui container {{if .IsWidthFull}}fluid padded{{end}}">
<div class="navbar">
{{template "repo/issue/navbar" .}}
<div class="ui right">
Expand Down