diff options
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/middlewares.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go index 3ee9d1a3e9..c99f0ee8f9 100644 --- a/routers/web/repo/middlewares.go +++ b/routers/web/repo/middlewares.go @@ -63,11 +63,29 @@ func SetDiffViewStyle(ctx *context.Context) { // SetWhitespaceBehavior set whitespace behavior as render variable func SetWhitespaceBehavior(ctx *context.Context) { + const defaultWhitespaceBehavior = "show-all" whitespaceBehavior := ctx.FormString("whitespace") switch whitespaceBehavior { - case "ignore-all", "ignore-eol", "ignore-change": - ctx.Data["WhitespaceBehavior"] = whitespaceBehavior + case "", "ignore-all", "ignore-eol", "ignore-change": + break default: - ctx.Data["WhitespaceBehavior"] = "" + whitespaceBehavior = defaultWhitespaceBehavior + } + if ctx.IsSigned { + userWhitespaceBehavior, err := user_model.GetUserSetting(ctx.User.ID, user_model.SettingsKeyDiffWhitespaceBehavior, defaultWhitespaceBehavior) + if err == nil { + if whitespaceBehavior == "" { + whitespaceBehavior = userWhitespaceBehavior + } else if whitespaceBehavior != userWhitespaceBehavior { + _ = user_model.SetUserSetting(ctx.User.ID, user_model.SettingsKeyDiffWhitespaceBehavior, whitespaceBehavior) + } + } // else: we can ignore the error safely + } + + // these behaviors are for gitdiff.GetWhitespaceFlag + if whitespaceBehavior == "" { + ctx.Data["WhitespaceBehavior"] = defaultWhitespaceBehavior + } else { + ctx.Data["WhitespaceBehavior"] = whitespaceBehavior } } |