From 3b66d03c3beb5d7af10f776b560c246ba5730291 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Wed, 22 Nov 2023 18:06:13 +0800 Subject: [PATCH] Revert "Fix EOL handling in web editor" (#28101) (#28172) Backport #28101 by @lng2020 Reverts go-gitea/gitea#27141 close #28097 Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com> (cherry picked from commit a2314ca9c5e17db140e66c7031cbfb97e04e41e5) --- routers/web/repo/editor.go | 2 +- templates/repo/editor/edit.tmpl | 7 +++---- web_src/js/features/codeeditor.js | 19 ++----------------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 1ad091b70f..5e7cd1caa3 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -287,7 +287,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b Operation: operation, FromTreePath: ctx.Repo.TreePath, TreePath: form.TreePath, - ContentReader: strings.NewReader(form.Content), + ContentReader: strings.NewReader(strings.ReplaceAll(form.Content, "\r", "")), }, }, Signoff: form.Signoff, diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl index 236f10bb0a..58ed6f356e 100644 --- a/templates/repo/editor/edit.tmpl +++ b/templates/repo/editor/edit.tmpl @@ -34,13 +34,12 @@ {{end}}
- + data-line-wrap-extensions="{{.LineWrapExtensions}}"> +{{.FileContent}}
diff --git a/web_src/js/features/codeeditor.js b/web_src/js/features/codeeditor.js index 5f924fd086..7dbbcd3dd6 100644 --- a/web_src/js/features/codeeditor.js +++ b/web_src/js/features/codeeditor.js @@ -62,7 +62,7 @@ export async function createMonaco(textarea, filename, editorOpts) { const monaco = await import(/* webpackChunkName: "monaco" */'monaco-editor'); initLanguages(monaco); - let {language, eol, ...other} = editorOpts; + let {language, ...other} = editorOpts; if (!language) language = getLanguage(filename); const container = document.createElement('div'); @@ -105,28 +105,14 @@ export async function createMonaco(textarea, filename, editorOpts) { monaco.languages.register({id: 'vs.editor.nullLanguage'}); monaco.languages.setLanguageConfiguration('vs.editor.nullLanguage', {}); - // We encode the initial value in JSON on the backend to prevent browsers from - // discarding the \r during HTML parsing: - // https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream - const value = JSON.parse(textarea.getAttribute('data-initial-value') || '""'); - textarea.value = value; - textarea.removeAttribute('data-initial-value'); - const editor = monaco.editor.create(container, { - value, + value: textarea.value, theme: 'gitea', language, ...other, }); const model = editor.getModel(); - - // Monaco performs auto-detection of dominant EOL in the file, biased towards LF for - // empty files. If there is an editorconfig value, override this detected value. - if (eol in monaco.editor.EndOfLineSequence) { - model.setEOL(monaco.editor.EndOfLineSequence[eol]); - } - model.onDidChangeContent(() => { textarea.value = editor.getValue(); textarea.dispatchEvent(new Event('change')); // seems to be needed for jquery-are-you-sure @@ -201,6 +187,5 @@ function getEditorConfigOptions(ec) { opts.trimAutoWhitespace = ec.trim_trailing_whitespace === true; opts.insertSpaces = ec.indent_style === 'space'; opts.useTabStops = ec.indent_style === 'tab'; - opts.eol = ec.end_of_line?.toUpperCase(); return opts; }