Skip to content

Diff view omits second blank line when inserting code between two methods

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

When editing a single file in GitLab’s Web IDE (Write → Preview Changes), inserting a new method between two existing methods causes the diff to show only one of the two blank lines you added. The second blank line (between your new method and the following original method) is dropped from the “changes” view.

Steps to reproduce

  1. Edit a file containing two methods, methodA and methodB, with exactly one blank line between them.

  2. In the Write tab, click between methodA and methodB and press Enter.

  3. Write your new method, for example:

    def methodC
      # ...
    end
  4. Press Enter after the end keyword, so that there is one blank line above and one blank line below your new method.

  5. Switch to the Preview Changes tab.

What is the current bug behavior?

  • The diff view shows the added methodC block and the blank line before it.
  • The blank line after methodC (i.e. between methodC and the original methodB) is not shown in the diff.

What is the expected correct behavior?

  • The diff should display both blank lines—that is, one before and one after the inserted method—so the full context of your insertion is visible.

Relevant logs and/or screenshots

Write tab:

Line 11 is a blank line image

Preview Changes tab:

Blank line is missing

image

Screen_Recording_2025-05-13_at_16.03.36

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Additional Notes

  • Confirmed that the missing blank line actually ends up in the file (it’s committed), it’s only omitted from the diff view.

image

Edited by 🤖 GitLab Bot 🤖