2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FIX: Selections getting deselected on FireFox.

This commit is contained in:
Guo Xiang Tan 2017-04-04 13:06:07 +08:00
parent ad44d2a400
commit 7f1c474e5b

View file

@ -55,7 +55,8 @@ export default Ember.Component.extend({
const { isIOS, isAndroid, isSafari } = this.capabilities;
const showAtEnd = isMobileDevice || isIOS || isAndroid;
// used to work around Safari losing selection
// Don't mess with the original range as it results in weird behaviours
// where certain browsers will deselect the selection
const clone = firstRange.cloneRange();
// create a marker element containing a single invisible character
@ -63,9 +64,9 @@ export default Ember.Component.extend({
markerElement.appendChild(document.createTextNode("\ufeff"));
// on mobile, collapse the range at the end of the selection
if (showAtEnd) { firstRange.collapse(); }
if (showAtEnd) { clone.collapse(); }
// insert the marker
firstRange.insertNode(markerElement);
clone.insertNode(markerElement);
// retrieve the position of the marker
const $markerElement = $(markerElement);