diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-08-08 18:44:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-08 10:44:19 +0000 |
commit | 4fc4f6e6341cd6115dd7ac6e03888df16c6f718e (patch) | |
tree | d35d3bdc78beba6ed1a1d8b319ca90981ddee0c4 /modules | |
parent | 20f47bbca932b1f6a5290fda3391928686ed0c24 (diff) | |
download | gitea-4fc4f6e6341cd6115dd7ac6e03888df16c6f718e.tar.gz gitea-4fc4f6e6341cd6115dd7ac6e03888df16c6f718e.zip |
Refactor "editorconfig" (#26391)
There are 2 kinds of ".Editorconfig" in code, one is `JSON string` for
the web edtior, another is `*editorconfig.Editorconfig` for the file
rendering (used by `TabSizeClass`)
This PR distinguish them with different names.
And by the way, change the default tab size from 8 to 4, I think few
people would like to use 8-size tabs nowadays.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/templates/util_misc.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/modules/templates/util_misc.go b/modules/templates/util_misc.go index 9cdabeb3ac..7700a13932 100644 --- a/modules/templates/util_misc.go +++ b/modules/templates/util_misc.go @@ -5,10 +5,10 @@ package templates import ( "context" - "fmt" "html/template" "mime" "path/filepath" + "strconv" "strings" "time" @@ -174,23 +174,12 @@ func FilenameIsImage(filename string) bool { return strings.HasPrefix(mimeType, "image/") } -func TabSizeClass(ec any, filename string) string { - var ( - value *editorconfig.Editorconfig - ok bool - ) +func TabSizeClass(ec *editorconfig.Editorconfig, filename string) string { if ec != nil { - if value, ok = ec.(*editorconfig.Editorconfig); !ok || value == nil { - return "tab-size-8" - } - def, err := value.GetDefinitionForFilename(filename) - if err != nil { - log.Error("tab size class: getting definition for filename: %v", err) - return "tab-size-8" - } - if def.TabWidth > 0 { - return fmt.Sprintf("tab-size-%d", def.TabWidth) + def, err := ec.GetDefinitionForFilename(filename) + if err == nil && def.TabWidth >= 1 && def.TabWidth <= 16 { + return "tab-size-" + strconv.Itoa(def.TabWidth) } } - return "tab-size-8" + return "tab-size-4" } |