Selection copy in div copies extra whitespace

NEW
Unassigned

Status

()

Core
Selection
2 years ago
2 years ago

People

(Reporter: dbkats, Unassigned)

Tracking

({testcase})

41 Branch
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [parity-chrome][parity-opera][parity-ie], URL)

(Reporter)

Description

2 years ago
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

Steps to reproduce:

Try this fidlde in Chrome and Firefox: https://jsfiddle.net/azwwux35/2/

HTML:
<div class="outer">
    <div class="copyable">CopyThis</div>
</div>
<input type="text" placeholder="paste here" />

JS (+JQuery):
$(".copyable").click(function (e) {
	var elem = e.target;
    var selection = window.getSelection();
    var range = document.createRange();
    range.selectNodeContents(elem);
    selection.removeAllRanges();
    selection.addRange(range);
});

Click the text "CopyThis", which will select it using Range and Selection APIs. Then paste it into the field with placeholder "paste here".




Actual results:

Text that is pasted is " CopyThis" instead of "CopyThis"


Expected results:

Copied text should be "CopyThis". This is what happens in Chrome. 

Note that if outer div does not exist, then behaviour is as expected.

Comment 1

2 years ago
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:44.0) Gecko/20100101 Firefox/44.0
20151011030229
Status: UNCONFIRMED → NEW
Component: Untriaged → Selection
Ever confirmed: true
Keywords: testcase
OS: Unspecified → All
Product: Firefox → Core
Hardware: Unspecified → All
Whiteboard: [parity-chrome][parity-opera][parity-ie]
You need to log in before you can comment on or make changes to this bug.