mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 06:52:54 +00:00
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.
This commit is contained in:
parent
20f47bbca9
commit
4fc4f6e634
3 changed files with 9 additions and 20 deletions
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue