summaryrefslogtreecommitdiffstats
path: root/routers/repo/middlewares.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/middlewares.go')
-rw-r--r--routers/repo/middlewares.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/routers/repo/middlewares.go b/routers/repo/middlewares.go
index 94e007cd20..757a049ab7 100644
--- a/routers/repo/middlewares.go
+++ b/routers/repo/middlewares.go
@@ -21,3 +21,24 @@ func SetEditorconfigIfExists(ctx *context.Context) {
ctx.Data["Editorconfig"] = ec
}
+
+func SetDiffViewStyle(ctx *context.Context) {
+ var (
+ userStyle = ctx.User.DiffViewStyle
+ queryStyle = ctx.Query("style")
+ style string
+ )
+
+ if queryStyle == "unified" || queryStyle == "split" {
+ style = queryStyle
+ } else if userStyle == "unified" || userStyle == "split" {
+ style = userStyle
+ } else {
+ style = "unified"
+ }
+
+ ctx.Data["IsSplitStyle"] = style == "split"
+ if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
+ ctx.Handle(500, "ErrUpdateDiffViewStyle", err)
+ }
+}