Commit df3c466e authored by Jo Hund's avatar Jo Hund

Don't remove trailing newline when editing a file in web UI editor:

* populate ACE editor content via API instead of HTML element inner text (to preserve trailing whitespace).
* remove hack in EditTreeController#preview that replaces any removed \n.

Fixes #5936
parent 024e0577
...@@ -28,8 +28,6 @@ class Projects::EditTreeController < Projects::BaseTreeController ...@@ -28,8 +28,6 @@ class Projects::EditTreeController < Projects::BaseTreeController
def preview def preview
@content = params[:content] @content = params[:content]
#FIXME workaround https://github.com/gitlabhq/gitlabhq/issues/5936
@content += "\n" if @blob.data.end_with?("\n")
diffy = Diffy::Diff.new(@blob.data, @content, diff: '-U 3', diffy = Diffy::Diff.new(@blob.data, @content, diff: '-U 3',
include_diff_info: true) include_diff_info: true)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
.btn-group.tree-btn-group .btn-group.tree-btn-group
= link_to "Cancel", @after_edit_path, class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message } = link_to "Cancel", @after_edit_path, class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message }
.file-content.code .file-content.code
%pre.js-edit-mode-pane#editor= @blob.data %pre.js-edit-mode-pane#editor
.js-edit-mode-pane#preview.hide .js-edit-mode-pane#preview.hide
.center .center
%h2 %h2
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace") ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace")
var ace_mode = "#{@blob.language.try(:ace_mode)}"; var ace_mode = "#{@blob.language.try(:ace_mode)}";
var editor = ace.edit("editor"); var editor = ace.edit("editor");
editor.setValue("#{escape_javascript(@blob.data)}");
if (ace_mode) { if (ace_mode) {
editor.getSession().setMode('ace/mode/' + ace_mode); editor.getSession().setMode('ace/mode/' + ace_mode);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment