Skip to content

Commit

Permalink
plugin.pdfViewerChildren now uses .pdf-container element instead of .…
Browse files Browse the repository at this point in the history
…pdf-viewer/.pdfViewer element in order to avoid confusion caused by the pdfViewerEl class name change
  • Loading branch information
RyotaUshio committed Dec 21, 2024
1 parent 9980160 commit 9058401
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,13 @@ export class PDFPlusLib {
}

getPDFViewerChildAssociatedWithNode(node: Node) {
// for (const [viewerEl, child] of this.plugin.pdfViwerChildren) {
// if (viewerEl.contains(node)) return child;
// }
let child: PDFViewerChild | undefined;

const el = node.instanceOf(HTMLElement) ? node : node.parentElement;
if (el) {
const viewerEl = el.closest<HTMLElement>('.pdf-viewer');
if (viewerEl) {
child = this.plugin.pdfViewerChildren.get(viewerEl);
const pdfContainerEl = el.closest<HTMLElement>('.pdf-container');
if (pdfContainerEl) {
child = this.plugin.pdfViewerChildren.get(pdfContainerEl);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class PDFPlus extends Plugin {
lastCopiedDestInfo: { file: TFile, destArray: DestArray } | { file: TFile, destName: string } | null = null;
vimrc: string | null = null;
citationIdRegex: RegExp;
/** Maps a `div.pdf-viewer` element to the corresponding `PDFViewerChild` object. */
/** Maps a `div.pdf-container` element to the corresponding `PDFViewerChild` object. */
// In most use cases of this map, the goal is also achieved by using lib.workspace.iteratePDFViewerChild.
// However, a PDF embed inside a Canvas text node cannot be handled by the function, so we need this map.
pdfViewerChildren: Map<HTMLElement, PDFViewerChild> = new Map();
Expand Down Expand Up @@ -550,8 +550,8 @@ export default class PDFPlus extends Plugin {
private registerEvents() {
// keep this.pdfViewerChildren up-to-date
this.registerEvent(this.app.workspace.on('layout-change', () => {
for (const viewerEl of this.pdfViewerChildren.keys()) {
if (!viewerEl?.isShown()) this.pdfViewerChildren.delete(viewerEl);
for (const pdfContainerEl of this.pdfViewerChildren.keys()) {
if (!pdfContainerEl?.isShown()) this.pdfViewerChildren.delete(pdfContainerEl);
}
}));

Expand Down
12 changes: 6 additions & 6 deletions src/patchers/pdf-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => {
},
onResize(old) {
return function (this: PDFViewerChild) {
const viewerEl = this.containerEl.querySelector<HTMLElement>('.pdf-viewer');
if (viewerEl) {
plugin.pdfViewerChildren.set(viewerEl, this);
const pdfContainerEl = this.containerEl.querySelector<HTMLElement>('.pdf-container');
if (pdfContainerEl) {
plugin.pdfViewerChildren.set(pdfContainerEl, this);
}

return old.call(this);
Expand Down Expand Up @@ -276,9 +276,9 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => {
await old.call(this, file, subpath);
}

const viewerEl = this.containerEl.querySelector<HTMLElement>('.pdf-viewer');
if (viewerEl) {
plugin.pdfViewerChildren.set(viewerEl, this);
const pdfContainerEl = this.containerEl.querySelector<HTMLElement>('.pdf-container');
if (pdfContainerEl) {
plugin.pdfViewerChildren.set(pdfContainerEl, this);
}

this.bib?.unload();
Expand Down

0 comments on commit 9058401

Please sign in to comment.