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 cca0f7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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
16 changes: 15 additions & 1 deletion web/caret_browsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ class CaretBrowsingMode {

#viewerContainer;

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

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 cca0f7b

Please sign in to comment.