From 4d730a759ae2349ff1cf76c31c10566e52f7d24e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 9 Jan 2024 04:00:47 -0800 Subject: [PATCH] Focus on the rename text area when it becomes visible --- js/main.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/js/main.js b/js/main.js index f63327ce..fda64bfc 100644 --- a/js/main.js +++ b/js/main.js @@ -397,3 +397,31 @@ function updateDocumentWidth() { updateDocumentWidth(); window.addEventListener("resize", updateDocumentWidth); + +//------------------------------------------------ +// Focus on the rename text area when it becomes visible +//------------------------------------------------ +const renameTextArea = document.getElementById('rename-row').querySelector('textarea'); + +function respondToVisibility(element, callback) { + var options = { + root: document.documentElement, + }; + + var observer = new IntersectionObserver((entries, observer) => { + entries.forEach(entry => { + callback(entry.intersectionRatio > 0); + }); + }, options); + + observer.observe(element); +} + + +function handleVisibilityChange(isVisible) { + if (isVisible) { + renameTextArea.focus(); + } +} + +respondToVisibility(renameTextArea, handleVisibilityChange);