From 1bd8975de92eef0dc41a649adeb33fa3dffd5237 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 20 Jan 2020 13:36:42 +0100 Subject: [PATCH] Selected text hidden in an element's overflow should not trigger the quote tooltip --- wcfsetup/install/files/js/WCF.Message.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index d94279d331..61b641d262 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1096,6 +1096,23 @@ if (COMPILER_TARGET_DEFAULT) { var startContainer = elClosest(range.startContainer, '.jsQuoteMessageContainer'); var endContainer = elClosest(range.endContainer, '.jsQuoteMessageContainer'); if (startContainer && startContainer === endContainer && !startContainer.classList.contains('jsInvalidQuoteTarget')) { + // Check if the selection is visible, such as text marked inside containers with an + // active overflow handling attached to it. This can be a side effect of the browser + // search which modifies the text selection, but cannot be distinguished from manual + // selections initiated by the user. + var commonAncestor = range.commonAncestorContainer; + if (commonAncestor.nodeType !== Node.ELEMENT_NODE) { + commonAncestor = commonAncestor.parentNode; + } + + var offsetParent = commonAncestor.offsetParent; + if (startContainer.contains(offsetParent)) { + if (offsetParent.scrollTop + offsetParent.clientHeight < commonAncestor.offsetTop) { + // The selected text is not visible to the user. + return; + } + } + this._activeContainerID = startContainer.id; } } -- 2.20.1