diff --git a/app/assets/javascripts/discourse/components/quote-button.js.es6 b/app/assets/javascripts/discourse/components/quote-button.js.es6 index 7fff911e5e7..77a5c8192a2 100644 --- a/app/assets/javascripts/discourse/components/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/components/quote-button.js.es6 @@ -15,6 +15,7 @@ export default Ember.Component.extend({ visible: buffer => buffer && buffer.length > 0, _isMouseDown: false, + _reselected: false, _selectionChanged() { const selection = window.getSelection(); @@ -38,17 +39,17 @@ 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 // on Mobile, shows the button at the end of the selection const isMobileDevice = this.site.isMobileDevice; - const { isIOS, isAndroid } = this.capabilities; + const { isIOS, isAndroid, isSafari } = this.capabilities; const showAtEnd = isMobileDevice || isIOS || isAndroid; + // used to work around Safari losing selection + const clone = firstRange.cloneRange(); + // create a marker element containing a single invisible character const markerElement = document.createElement("span"); markerElement.appendChild(document.createTextNode("\ufeff")); @@ -68,9 +69,11 @@ export default Ember.Component.extend({ markerElement.parentNode.removeChild(markerElement); // work around Safari that would sometimes lose the selection - const s = window.getSelection(); - s.removeAllRanges(); - s.addRange(clone); + if (isSafari) { + this._reselected = true; + selection.removeAllRanges(); + selection.addRange(clone); + } // change the position of the button Ember.run.scheduleOnce("afterRender", () => { @@ -96,6 +99,7 @@ export default Ember.Component.extend({ $(document).on("mousedown.quote-button", (e) => { this._isMouseDown = true; + this._reselected = false; if (!willQuote(e)) { this.sendAction("deselectText"); } @@ -103,7 +107,7 @@ export default Ember.Component.extend({ this._isMouseDown = false; onSelectionChanged(); }).on("selectionchange.quote-button", () => { - if (!this._isMouseDown) { + if (!this._isMouseDown && !this._reselected) { onSelectionChanged(); } });