Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/quickTools/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const SearchRow1 = ({ inputRef }) => (
<RowItem id="search-prev" icon="arrow_back" action="search-prev" />
<RowItem id="search-next" icon="arrow_forward" action="search-next" />
<RowItem id="search-settings" icon="settings" action="search-settings" />
<RowItem id="close" icon="clearclose" action="toggle" />
</div>
);

Expand Down
11 changes: 11 additions & 0 deletions src/components/quickTools/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
@use '../../styles/mixins.scss';

#quick-tools {
#search_row1 {
[data-id="close"] {
display: none;
flex: 0 0 40px;
}

&.inline-close [data-id="close"] {
display: inline-flex;
}
}

.icon.click:not([disabled]) {
@include mixins.active-icon;
transition: all 0.3s ease-in-out;
Expand Down
34 changes: 34 additions & 0 deletions src/handlers/quickTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ let input;
/** @type {number} */
let quickToolUsedTimeout = null;
let activeSearchState = null;
/** @type {MutationObserver | null} */
let searchCloseVisibilityObserver = null;

const state = {
shift: false,
Expand Down Expand Up @@ -438,6 +440,7 @@ function toggleSearch() {
activeSearchState = { className, content: $content, footerHeight };

$toggler.className = "floating icon clearclose";
startSearchCloseVisibilitySync();
$footer.content = [$searchRow1, $searchRow2];
clearSearchQuickToolsState($content);
setRefValue($searchInput, selectedText || "");
Expand Down Expand Up @@ -469,6 +472,7 @@ function toggleSearch() {
content: $content,
footerHeight,
};
stopSearchCloseVisibilitySync();
clearSearchQuickToolsState(restoreState.content);
removeSearch();
clearQuickToolsButtonFeedback(restoreState.content);
Expand All @@ -493,6 +497,36 @@ function toggleSearch() {
$searchInput.focus();
}

function startSearchCloseVisibilitySync() {
stopSearchCloseVisibilitySync();
syncSearchCloseVisibility();

const { $toggler } = quickTools;
searchCloseVisibilityObserver = new MutationObserver(
syncSearchCloseVisibility,
);
searchCloseVisibilityObserver.observe(root, { childList: true });
searchCloseVisibilityObserver.observe($toggler, {
attributes: true,
attributeFilter: ["class"],
});
}

function stopSearchCloseVisibilitySync() {
searchCloseVisibilityObserver?.disconnect();
searchCloseVisibilityObserver = null;
quickTools.$searchRow1.classList.remove("inline-close");
}

function syncSearchCloseVisibility() {
const { $searchRow1, $toggler } = quickTools;
const hasVisibleFloatingClose =
appSettings.value.floatingButton &&
$toggler.isConnected &&
!$toggler.classList.contains("hide");
$searchRow1.classList.toggle("inline-close", !hasVisibleFloatingClose);
}

function toggle() {
// if search is active, remove it
const searchBar = actionStack.get("search-bar");
Expand Down