Skip to content

Commit

Permalink
Update the CaretBrowsingMode toolbar-height if the toolbarDensity
Browse files Browse the repository at this point in the history
… preference changes (PR 18786 follow-up)

Otherwise the isVisible-calculations may not work correctly.
  • Loading branch information
Snuffleupagus committed Oct 1, 2024
1 parent f2a132f commit 7c9d177
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ const PDFViewerApplication = {

moveCaret(isUp, select) {
this._caretBrowsing ||= new CaretBrowsingMode(
this._globalAbortController.signal,
this.appConfig.mainContainer,
this.appConfig.viewerContainer,
this.appConfig.toolbar?.container
Expand Down
24 changes: 21 additions & 3 deletions web/caret_browsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@ const PRECISION = 1e-1;
class CaretBrowsingMode {
#mainContainer;

#toolBarHeight;
#toolBarHeight = 0;

#viewerContainer;

constructor(mainContainer, viewerContainer, toolbarContainer) {
constructor(abortSignal, mainContainer, viewerContainer, toolbarContainer) {
this.#mainContainer = mainContainer;
this.#viewerContainer = viewerContainer;
this.#toolBarHeight = toolbarContainer?.getBoundingClientRect().height ?? 0;

if (!toolbarContainer) {
return;
}
this.#toolBarHeight = toolbarContainer.getBoundingClientRect().height;

const toolbarObserver = new ResizeObserver(entries => {
for (const entry of entries) {
if (entry.target === toolbarContainer) {
this.#toolBarHeight = Math.floor(entry.borderBoxSize[0].blockSize);
break;
}
}
});
toolbarObserver.observe(toolbarContainer);

abortSignal.addEventListener("abort", () => toolbarObserver.disconnect(), {
once: true,
});
}

/**
Expand Down

0 comments on commit 7c9d177

Please sign in to comment.