提交 e373fd0c 编写于 作者: T Thottyottyotty

rewrite uiElementIsVisible

rewrite visibility checking to be more generic/cleaner as well as add functionality to check if the element is scrolled on screen for more intuitive paste-target selection
上级 a375acdd
...@@ -92,19 +92,17 @@ document.addEventListener('keydown', function(e) { ...@@ -92,19 +92,17 @@ document.addEventListener('keydown', function(e) {
* checks that a UI element is not in another hidden element or tab content * checks that a UI element is not in another hidden element or tab content
*/ */
function uiElementIsVisible(el) { function uiElementIsVisible(el) {
let isVisible = !el.closest('.\\!hidden'); if (el === document) {
if (!isVisible) { return true;
return false;
} }
while ((isVisible = el.closest('.tabitem')?.style.display) !== 'none') { const computedStyle = getComputedStyle(el);
if (!isVisible) { const isVisible = computedStyle.display !== 'none';
return false;
} else if (el.parentElement) { const clRect = el.getBoundingClientRect();
el = el.parentElement; const windowHeight = window.innerHeight;
} else { const onScreen = clRect.bottom > 0 && clRect.top < windowHeight;
break;
} if (!isVisible || !onScreen) return false;
} return uiElementIsVisible(el.parentNode);
return isVisible;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册