From e3b47a399819b373f29b9036bdd2df553ba9c377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 25 Nov 2016 17:55:39 +0100 Subject: [PATCH] FIX: hide quote button when the selection is expanded to more than 1 post --- .../discourse/components/quote-button.js.es6 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/components/quote-button.js.es6 b/app/assets/javascripts/discourse/components/quote-button.js.es6 index dd1fea1d70e..b6012ed4550 100644 --- a/app/assets/javascripts/discourse/components/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/components/quote-button.js.es6 @@ -18,19 +18,24 @@ export default Ember.Component.extend({ _selectionChanged() { const selection = window.getSelection(); - if (selection.isCollapsed) { return; } + if (selection.isCollapsed) { + if (this.get("visible")) this.sendAction("deselectText"); + return; + } - // ensure we selected content inside 1 post + // ensure we selected content inside 1 post *only* let firstRange, postId; for (let r = 0; r < selection.rangeCount; r++) { const range = selection.getRangeAt(r); - firstRange = firstRange || range; - const $ancestor = $(range.commonAncestorContainer); - if ($ancestor.closest(".contents").length === 0) { return; } + firstRange = firstRange || range; postId = postId || $ancestor.closest('.boxed, .reply').data('post-id'); - if (!postId) { return; } + + if ($ancestor.closest(".contents").length === 0 || !postId) { + if (this.get("visible")) this.sendAction("deselectText"); + return; + } } this.get("quoteState").setProperties({ postId, buffer: selectedText() });