Skip to content

Commit 3e36104

Browse files
committed
Add ui.EDITOR_EOL setting and use ist instead of monaco's detection
1 parent 2de05f9 commit 3e36104

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,9 @@ LEVEL = Info
12421242
;; Change the sort type of the explore pages.
12431243
;; Default is "recentupdate", but you also have "alphabetically", "reverselastlogin", "newest", "oldest".
12441244
;EXPLORE_PAGING_DEFAULT_SORT = recentupdate
1245+
;;
1246+
;; Default line ending format for the web editor. Either `LF` or `CRLF`. Can be overridden with .editorconfig.
1247+
;EDITOR_EOL = LF
12451248

12461249
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12471250
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
232232
- `ONLY_SHOW_RELEVANT_REPOS`: **false**: Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
233233
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
234234
- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid values are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest"
235+
- `EDITOR_EOL`: **LF**: Default line ending format for the web editor. Either `LF` or `CRLF`. Can be overridden with .editorconfig.
235236

236237
### UI - Admin (`ui.admin`)
237238

modules/setting/ui.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var UI = struct {
3434
SearchRepoDescription bool
3535
OnlyShowRelevantRepos bool
3636
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
37+
EditorEol string `ini:"EDITOR_EOL"`
3738

3839
Notification struct {
3940
MinTimeout time.Duration
@@ -82,6 +83,7 @@ var UI = struct {
8283
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
8384
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
8485
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
86+
EditorEol: `LF`,
8587
Notification: struct {
8688
MinTimeout time.Duration
8789
TimeoutStep time.Duration

modules/templates/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ func NewFuncMap() template.FuncMap {
149149
"MermaidMaxSourceCharacters": func() int {
150150
return setting.MermaidMaxSourceCharacters
151151
},
152+
"EditorEol": func() string {
153+
return setting.UI.EditorEol
154+
},
152155

153156
// -----------------------------------------------------------------
154157
// render

templates/base/head_script.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
4242
modal_confirm: {{ctx.Locale.Tr "modal.confirm"}},
4343
modal_cancel: {{ctx.Locale.Tr "modal.cancel"}},
4444
},
45+
editorEol: '{{EditorEol}}',
4546
};
4647
{{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}}
4748
window.config.pageData = window.config.pageData || {};

web_src/js/features/codeeditor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {onInputDebounce} from '../utils/dom.js';
44

55
const languagesByFilename = {};
66
const languagesByExt = {};
7+
const {editorEol} = window.config;
78

89
const baseOptions = {
910
fontFamily: 'var(--fonts-monospace)',
@@ -62,7 +63,7 @@ export async function createMonaco(textarea, filename, editorOpts) {
6263
const monaco = await import(/* webpackChunkName: "monaco" */'monaco-editor');
6364

6465
initLanguages(monaco);
65-
let {language, eol, ...other} = editorOpts;
66+
let {language, eol: editorConfigEol, ...other} = editorOpts;
6667
if (!language) language = getLanguage(filename);
6768

6869
const container = document.createElement('div');
@@ -121,8 +122,8 @@ export async function createMonaco(textarea, filename, editorOpts) {
121122

122123
const model = editor.getModel();
123124

124-
// Monaco performs auto-detection of dominant EOL in the file, biased towards LF for
125-
// empty files. If there is an editorconfig value, override this detected value.
125+
// Use eol format from editorconfig if present, otherwise fall back to ui.EDITOR_EOL
126+
const eol = editorConfigEol ?? editorEol;
126127
if (eol in monaco.editor.EndOfLineSequence) {
127128
model.setEOL(monaco.editor.EndOfLineSequence[eol]);
128129
}

0 commit comments

Comments
 (0)