From 965b38ff2a63fa3c7e2d174be2cbd01398839454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 5 Dec 2016 11:08:30 +0100 Subject: [PATCH] FIX: safari would lose selection sometimes --- .../javascripts/discourse/components/quote-button.js.es6 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/javascripts/discourse/components/quote-button.js.es6 b/app/assets/javascripts/discourse/components/quote-button.js.es6 index b6012ed4550..7fff911e5e7 100644 --- a/app/assets/javascripts/discourse/components/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/components/quote-button.js.es6 @@ -38,6 +38,9 @@ export default Ember.Component.extend({ } } + // used to work around Safari losing selection + const clone = firstRange.cloneRange(); + this.get("quoteState").setProperties({ postId, buffer: selectedText() }); // on Desktop, shows the button at the beginning of the selection @@ -64,6 +67,11 @@ export default Ember.Component.extend({ // remove the marker markerElement.parentNode.removeChild(markerElement); + // work around Safari that would sometimes lose the selection + const s = window.getSelection(); + s.removeAllRanges(); + s.addRange(clone); + // change the position of the button Ember.run.scheduleOnce("afterRender", () => { let top = markerOffset.top;