Skip to content

Commit 44e6a37

Browse files
committed
fix
1 parent 9ca191e commit 44e6a37

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

‎src/handlers/quickTools.js‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ let input;
3333
/** @type {number} */
3434
let quickToolUsedTimeout = null;
3535
let activeSearchState = null;
36+
/** @type {MutationObserver | null} */
37+
let searchCloseVisibilityObserver = null;
3638

3739
const state = {
3840
shift: false,
@@ -438,10 +440,7 @@ function toggleSearch() {
438440
activeSearchState = { className, content: $content, footerHeight };
439441

440442
$toggler.className = "floating icon clearclose";
441-
$searchRow1.classList.toggle(
442-
"inline-close",
443-
!appSettings.value.floatingButton || !$toggler.isConnected,
444-
);
443+
startSearchCloseVisibilitySync();
445444
$footer.content = [$searchRow1, $searchRow2];
446445
clearSearchQuickToolsState($content);
447446
setRefValue($searchInput, selectedText || "");
@@ -473,6 +472,7 @@ function toggleSearch() {
473472
content: $content,
474473
footerHeight,
475474
};
475+
stopSearchCloseVisibilitySync();
476476
clearSearchQuickToolsState(restoreState.content);
477477
removeSearch();
478478
clearQuickToolsButtonFeedback(restoreState.content);
@@ -497,6 +497,36 @@ function toggleSearch() {
497497
$searchInput.focus();
498498
}
499499

500+
function startSearchCloseVisibilitySync() {
501+
stopSearchCloseVisibilitySync();
502+
syncSearchCloseVisibility();
503+
504+
const { $toggler } = quickTools;
505+
searchCloseVisibilityObserver = new MutationObserver(
506+
syncSearchCloseVisibility,
507+
);
508+
searchCloseVisibilityObserver.observe(root, { childList: true });
509+
searchCloseVisibilityObserver.observe($toggler, {
510+
attributes: true,
511+
attributeFilter: ["class"],
512+
});
513+
}
514+
515+
function stopSearchCloseVisibilitySync() {
516+
searchCloseVisibilityObserver?.disconnect();
517+
searchCloseVisibilityObserver = null;
518+
quickTools.$searchRow1.classList.remove("inline-close");
519+
}
520+
521+
function syncSearchCloseVisibility() {
522+
const { $searchRow1, $toggler } = quickTools;
523+
const hasVisibleFloatingClose =
524+
appSettings.value.floatingButton &&
525+
$toggler.isConnected &&
526+
!$toggler.classList.contains("hide");
527+
$searchRow1.classList.toggle("inline-close", !hasVisibleFloatingClose);
528+
}
529+
500530
function toggle() {
501531
// if search is active, remove it
502532
const searchBar = actionStack.get("search-bar");

0 commit comments

Comments
 (0)