diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index a4e13c5ca8..96fa878b5e 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -148,6 +148,13 @@ "filter.private": "Private", "no_results_found": "No results found.", "internal_error_skipped": "Internal error occurred but is skipped: %s", + "characters_spaces": "Spaces", + "characters_tabs": "Tabs", + "text_indent_style": "Indent style", + "text_indent_size": "Indent size", + "text_line_wrap": "Wrap", + "text_line_nowrap": "No wrap", + "text_line_wrap_mode": "Line wrap mode", "search.search": "Search…", "search.type_tooltip": "Search type", "search.fuzzy": "Fuzzy", diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 048c9f3d4a..171ccd7719 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -18,7 +18,6 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/util" @@ -78,8 +77,6 @@ func prepareEditorPageFormOptions(ctx *context.Context, editorAction string) *co ctx.Data["CommitFormOptions"] = commitFormOptions // for online editor - ctx.Data["PreviewableExtensions"] = strings.Join(markup.PreviewableExtensions(), ",") - ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",") ctx.Data["IsEditingFileOnly"] = ctx.FormString("return_uri") != "" ctx.Data["ReturnURI"] = ctx.FormString("return_uri") @@ -321,7 +318,7 @@ func EditFile(ctx *context.Context) { } } - ctx.Data["EditorconfigJson"] = getContextRepoEditorConfig(ctx, ctx.Repo.TreePath) + ctx.Data["CodeEditorConfig"] = getCodeEditorConfig(ctx, ctx.Repo.TreePath) ctx.HTML(http.StatusOK, tplEditFile) } diff --git a/routers/web/repo/editor_apply_patch.go b/routers/web/repo/editor_apply_patch.go index 357c6f3a21..1a01bfd5cb 100644 --- a/routers/web/repo/editor_apply_patch.go +++ b/routers/web/repo/editor_apply_patch.go @@ -20,6 +20,7 @@ func NewDiffPatch(ctx *context.Context) { } ctx.Data["PageIsPatch"] = true + ctx.Data["CodeEditorConfig"] = CodeEditorConfig{} // not really editing a file, so no need to fill in the config ctx.HTML(http.StatusOK, tplPatchFile) } diff --git a/routers/web/repo/editor_util.go b/routers/web/repo/editor_util.go index 07bcb474f0..aca732ac70 100644 --- a/routers/web/repo/editor_util.go +++ b/routers/web/repo/editor_util.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "path" + "strconv" "strings" git_model "code.gitea.io/gitea/models/git" @@ -14,9 +15,11 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" - "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/markup" repo_module "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" context_service "code.gitea.io/gitea/services/context" ) @@ -62,17 +65,33 @@ func getClosestParentWithFiles(gitRepo *git.Repository, branchName, originTreePa return f(originTreePath, commit) } -// getContextRepoEditorConfig returns the editorconfig JSON string for given treePath or "null" -func getContextRepoEditorConfig(ctx *context_service.Context, treePath string) string { +// CodeEditorConfig is also used by frontend, defined in "codeeditor.ts" +type CodeEditorConfig struct { + PreviewableExtensions []string `json:"previewable_extensions"` + LineWrapExtensions []string `json:"line_wrap_extensions"` + LineWrapOn bool `json:"line_wrap_on"` + + IndentStyle string `json:"indent_style"` + IndentSize int `json:"indent_size"` + TabWidth int `json:"tab_width"` + TrimTrailingWhitespace *bool `json:"trim_trailing_whitespace,omitempty"` +} + +func getCodeEditorConfig(ctx *context_service.Context, treePath string) (ret CodeEditorConfig) { + ret.PreviewableExtensions = markup.PreviewableExtensions() + ret.LineWrapExtensions = setting.Repository.Editor.LineWrapExtensions + ret.LineWrapOn = util.SliceContainsString(ret.LineWrapExtensions, path.Ext(treePath), true) ec, _, err := ctx.Repo.GetEditorconfig() if err == nil { def, err := ec.GetDefinitionForFilename(treePath) if err == nil { - jsonStr, _ := json.Marshal(def) - return string(jsonStr) + ret.IndentStyle = def.IndentStyle + ret.IndentSize, _ = strconv.Atoi(def.IndentSize) + ret.TabWidth = def.TabWidth + ret.TrimTrailingWhitespace = def.TrimTrailingWhitespace } } - return "null" + return ret } // getParentTreeFields returns list of parent tree names and corresponding tree paths based on given treePath. diff --git a/routers/web/repo/setting/git_hooks.go b/routers/web/repo/setting/git_hooks.go index ba4b5e85b6..1f542a3f9f 100644 --- a/routers/web/repo/setting/git_hooks.go +++ b/routers/web/repo/setting/git_hooks.go @@ -7,6 +7,7 @@ import ( "net/http" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/routers/web/repo" "code.gitea.io/gitea/services/context" ) @@ -41,6 +42,7 @@ func GitHooksEdit(ctx *context.Context) { return } ctx.Data["Hook"] = hook + ctx.Data["CodeEditorConfig"] = repo.CodeEditorConfig{} // not really editing a repo file, so no editor config ctx.HTML(http.StatusOK, tplGithookEdit) } diff --git a/tailwind.config.ts b/tailwind.config.ts index 8693208e13..7aaea687eb 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -80,10 +80,10 @@ export default { semibold: 'var(--font-weight-semibold)', bold: 'var(--font-weight-bold)', }, - fontSize: { // not using `rem` units because our root is currently 14px - 'xs': '12px', - 'sm': '14px', - 'base': '16px', + fontSize: { // rarely used, but "text-base" (matching body's 1em=14px) is useful to reset font-size in a header container + 'xs': '11px', + 'sm': '12px', + 'base': '14px', 'lg': '18px', 'xl': '20px', '2xl': '24px', diff --git a/templates/package/content/container.tmpl b/templates/package/content/container.tmpl index 1a1335aaa6..a69b0477d2 100644 --- a/templates/package/content/container.tmpl +++ b/templates/package/content/container.tmpl @@ -78,7 +78,7 @@ {{ctx.Locale.Tr "packages.container.layers"}} {{/* only show the platform if the image metadata is not the package's, which means that it is a sub manifest */}} {{if ne .ContainerImageMetadata .PackageDescriptor.Metadata}} - + ({{svg "octicon-cpu" 12}} {{.ContainerImageMetadata.Platform}}) {{end}} diff --git a/templates/repo/editor/common_breadcrumb.tmpl b/templates/repo/editor/common_breadcrumb.tmpl index 8cfbe09d3e..44c9058457 100644 --- a/templates/repo/editor/common_breadcrumb.tmpl +++ b/templates/repo/editor/common_breadcrumb.tmpl @@ -5,7 +5,7 @@ {{range $i, $v := .TreeNames}} {{if eq $i $l}} - + {{svg "octicon-info"}} {{else}} {{$v}} diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl index 008376ce16..8a5ed4a39c 100644 --- a/templates/repo/editor/edit.tmpl +++ b/templates/repo/editor/edit.tmpl @@ -18,19 +18,22 @@ {{if not .NotEditableReason}}
-
+ data-previewable-extensions="{{StringUtils.Join $.CodeEditorConfig.PreviewableExtensions ","}}" + data-line-wrap-extensions="{{StringUtils.Join $.CodeEditorConfig.LineWrapExtensions ","}}">{{.FileContent}}
diff --git a/templates/repo/editor/options.tmpl b/templates/repo/editor/options.tmpl new file mode 100644 index 0000000000..04cbd44cd6 --- /dev/null +++ b/templates/repo/editor/options.tmpl @@ -0,0 +1,30 @@ +{{$indentStyle := $.CodeEditorConfig.IndentStyle}} +{{$indentSize := or $.CodeEditorConfig.IndentSize 4}} +{{$lineWrapOn := $.CodeEditorConfig.LineWrapOn}} +
+
+ +
+
+ +
+
+ +
+
diff --git a/templates/repo/editor/patch.tmpl b/templates/repo/editor/patch.tmpl index 9b82bb855f..a70464dacb 100644 --- a/templates/repo/editor/patch.tmpl +++ b/templates/repo/editor/patch.tmpl @@ -20,15 +20,20 @@
-