diff --git a/CHANGELOG b/CHANGELOG
index 6ff06091f618d7bc5c0231b29837b63388d2ecdd..7f9dfd98cd7a5659511e8869f0da9ea4938bd2c0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -54,6 +54,7 @@ v 8.3.0 (unreleased)
   - Suppress warning about missing `.gitlab-ci.yml` if builds are disabled
   - Do not show build status unless builds are enabled and `.gitlab-ci.yml` is present
   - Persist runners registration token in database
+  - Fix online editor should not remove newlines at the end of the file
 
 v 8.2.3
   - Fix application settings cache not expiring after changes (Stan Hu)
diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml
index 333f5d470ed310c771b109d9dcc2c7384355e757..10b02813733de0af679b8b8b281e6e020ede97a8 100644
--- a/app/views/projects/blob/_editor.html.haml
+++ b/app/views/projects/blob/_editor.html.haml
@@ -16,8 +16,7 @@
       = select_tag :encoding, options_for_select([ "base64", "text" ], "text"), class: 'select2'
 
   .file-content.code
-    %pre.js-edit-mode-pane#editor
-      = params[:content] || local_assigns[:blob_data]
+    %pre.js-edit-mode-pane#editor #{params[:content] || local_assigns[:blob_data]}
     - if local_assigns[:path]
       .js-edit-mode-pane#preview.hide
         .center
diff --git a/features/project/source/browse_files.feature b/features/project/source/browse_files.feature
index 439787f2641e5b44c3ecec19462a6aacfe62fb94..02159ee3776e9dafa46905e7f0bb248946b31ba8 100644
--- a/features/project/source/browse_files.feature
+++ b/features/project/source/browse_files.feature
@@ -34,6 +34,17 @@ Feature: Project Source Browse Files
     Then I am redirected to the new file
     And I should see its new content
 
+  @javascript
+  Scenario: I can create and commit file with new lines at the end of file
+    Given I click on "New file" link in repo
+    And I edit code with new lines at end of file
+    And I fill the new file name
+    And I fill the commit message
+    And I click on "Commit Changes"
+    Then I am redirected to the new file
+    And I click button "Edit"
+    And I should see its content with new lines preserved at end of file
+
   @javascript
   Scenario: I can upload file and commit
     Given I click on "Upload file" link in repo
diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb
index f2b957642673ed0a02b8ad9a47ec3b9a678c90db..b88709620ab82f7e90c1cd21f5c32eed629236aa 100644
--- a/features/steps/project/source/browse_files.rb
+++ b/features/steps/project/source/browse_files.rb
@@ -37,6 +37,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
     expect(page).to have_content new_gitignore_content
   end
 
+  step 'I should see its content with new lines preserved at end of file' do
+    expect(evaluate_script('blob.editor.getValue()')).to eq "Sample\n\n\n"
+  end
+
   step 'I click link "Raw"' do
     click_link 'Raw'
   end
@@ -62,6 +66,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
     set_new_content
   end
 
+  step 'I edit code with new lines at end of file' do
+    execute_script('blob.editor.setValue("Sample\n\n\n")')
+  end
+
   step 'I fill the new file name' do
     fill_in :file_name, with: new_file_name
   end