]> source.dussan.org Git - gitea.git/commitdiff
Revert "Fix EOL handling in web editor" (#28101)
authorNanguan Lin <70063547+lng2020@users.noreply.github.com>
Wed, 22 Nov 2023 09:14:16 +0000 (17:14 +0800)
committerGitHub <noreply@github.com>
Wed, 22 Nov 2023 09:14:16 +0000 (09:14 +0000)
Reverts go-gitea/gitea#27141
close #28097

routers/web/repo/editor.go
templates/repo/editor/edit.tmpl
web_src/js/features/codeeditor.js

index 1ad091b70fd9d780b753d9c2f0e06aa012e71e5e..5e7cd1caa39952229ad8a3944acc265f2b21eeaf 100644 (file)
@@ -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,
index 236f10bb0ad4e9cf39685682c09c775064a6f83a..58ed6f356e71a12603a6adc0109aa1c953a8ca6a 100644 (file)
                                        {{end}}
                                </div>
                                <div class="ui bottom attached active tab segment" data-tab="write">
-                                       <textarea id="edit_area" name="content" class="gt-hidden"
-                                               data-id="repo-{{.Repository.Name}}-{{.TreePath}}"
+                                       <textarea id="edit_area" name="content" class="gt-hidden" data-id="repo-{{.Repository.Name}}-{{.TreePath}}"
                                                data-url="{{.Repository.Link}}/markup"
                                                data-context="{{.RepoLink}}"
                                                data-previewable-extensions="{{.PreviewableExtensions}}"
-                                               data-line-wrap-extensions="{{.LineWrapExtensions}}"
-                                               data-initial-value="{{JsonUtils.EncodeToString .FileContent}}"></textarea>
+                                               data-line-wrap-extensions="{{.LineWrapExtensions}}">
+{{.FileContent}}</textarea>
                                        <div class="editor-loading is-loading"></div>
                                </div>
                                <div class="ui bottom attached tab segment markup" data-tab="preview">
index 5f924fd0864cf0509a85340a7522b8750f61a9d8..7dbbcd3dd62a9b5c2fa2bc792a2f9938a9e30f76 100644 (file)
@@ -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;
 }