diff options
author | Viktor Suprun <popsul1993@gmail.com> | 2022-02-08 17:15:04 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 14:15:04 +0800 |
commit | 4d939845d20d377e06bce5b02667ff21f69c3beb (patch) | |
tree | 3cfc0c54b5930a71c404961c26e7ae9e76060ffb /routers/web | |
parent | 60f203385e6f27fae47f3cc8c5d71309f4fd88dc (diff) | |
download | gitea-4d939845d20d377e06bce5b02667ff21f69c3beb.tar.gz gitea-4d939845d20d377e06bce5b02667ff21f69c3beb.zip |
Added auto-save whitespace behavior if it changed manually (#15566)
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 } } |