Skip to content
Snippets Groups Projects

Don't copy empty elements that were not selected on purpose as GFM

Merged Douwe Maan requested to merge dm-copy-as-gfm-without-empty-elements into master
All threads resolved!

You can reproduce the bug this fixes right here in GitLab <9.3 by triple clicking "Heading 1" below, and either hitting r or copy-pasting the selection into the GFM textarea below. Tested in Chrome.


Heading 1

Heading 2


You'll see that in the inserted text, there is an extra heading without any content:

# Heading 1

## 

The reason is that when you triple-click a block-level element (in Chrome at least), it actually selects that element, as well as an empty copy of the the element that follows it. In the example above, this looks like:

<h1>Heading1</h1>

<h2></h2>

Before this change, our Copy-as-GFM logic would happily translate this <h2>[nothing]</h2> to ## [nothing], hence the result above.

With this change, we automatically trim when appropriate, and skip empty elements that need text in Markdown, so that the selection described above will result in the below, as expected:

# Heading 1

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • This LGTM, but could we add an extra test for this?

  • Douwe Maan resolved all discussions

    resolved all discussions

  • assigned to @filipa

  • Douwe Maan added 1 commit

    added 1 commit

    Compare with previous version

  • Filipa Lacerda
  • @DouweM do we have tests for this? Thanks!

  • assigned to @DouweM

  • ups :see_no_evil: missed the test! :thumbsup:

  • assigned to @filipa

  • Douwe Maan resolved all discussions

    resolved all discussions

  • Douwe Maan added 1 commit

    added 1 commit

    • 6ec1f1a7 - Remove unnecessary variable

    Compare with previous version

  • Thank you @DouweM :tada:

  • Filipa Lacerda approved this merge request

    approved this merge request

  • Filipa Lacerda mentioned in commit c013d23d

    mentioned in commit c013d23d

  • Please register or sign in to reply
    Loading