Skip to content

Commit

Permalink
#68: hide reply annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Mar 1, 2024
1 parent 27f2fd1 commit 87497f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/patchers/pdf-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,23 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => {
const { source: pageView } = data;

pageView.annotationLayer?.div
?.querySelectorAll<HTMLElement>('section.linkAnnotation[data-internal-link][data-annotation-id]')
?.querySelectorAll<HTMLElement>('section[data-annotation-id]')
.forEach((el) => {
const annotationId = el.dataset.annotationId;
if (!annotationId) return;

const annot = pageView.annotationLayer?.annotationLayer.getAnnotation(annotationId);
if (!annot) return;

PDFInternalLinkPostProcessor.registerEvents(plugin, self, annot);
if (annot.data.subtype === 'Link' && typeof annot.container.dataset.internalLink === 'string') {
PDFInternalLinkPostProcessor.registerEvents(plugin, self, annot);
}

// Avoid rendering annotations that are replies to other annotations
// https://github.com/RyotaUshio/obsidian-pdf-plus/issues/68
if (plugin.settings.hideReplyAnnotation && annot.data.inReplyTo && annot.data.replyType === 'R') {
annot.container.hide();
}
});
});

Expand Down Expand Up @@ -229,7 +237,7 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => {
const view = lib.workspace.getActivePDFView();
if (view && view.viewer.child === self) {
const override = { state: { file: self.file!.path, page: pageNumber } };
this.app.workspace.trigger('view-sync:state-change', view, override);
app.workspace.trigger('view-sync:state-change', view, override);
}
}
}, plugin.settings.viewSyncPageDebounceInterval * 1000)
Expand Down
12 changes: 11 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export interface PDFPlusSettings {
showBacklinkIconForOffset: boolean;
showBacklinkIconForRect: boolean;
showBoundingRectForBacklinkedAnnot: boolean;
hideReplyAnnotation: boolean;
}

export const DEFAULT_SETTINGS: PDFPlusSettings = {
Expand Down Expand Up @@ -397,6 +398,7 @@ export const DEFAULT_SETTINGS: PDFPlusSettings = {
showBacklinkIconForOffset: true,
showBacklinkIconForRect: false,
showBoundingRectForBacklinkedAnnot: false,
hideReplyAnnotation: false,
};


Expand Down Expand Up @@ -443,7 +445,6 @@ export class PDFPlusSettingTab extends PluginSettingTab {
parentEl.insertBefore(createDiv('spacer'), setting.settingEl);
}

setting.nameEl.appendChild(createSpan({ text: heading }));
if (icon) {
const parentEl = setting.settingEl.parentElement;
if (parentEl) {
Expand Down Expand Up @@ -2022,6 +2023,15 @@ export class PDFPlusSettingTab extends PluginSettingTab {
});
});
}
this.addToggleSetting('hideReplyAnnotation')
.setName('Hide reply annotations')
.then((setting) => {
this.renderMarkdown([
'Hide annotations that are replies to other annotations in the PDF viewer.',
'',
'This is a temporary fix for the issue that PDF.js (the library Obsidian\'s PDF viewer is based on) does not fulfill the PDF specification in that it renders reply annotations as if a standalone annotation.',
], setting.descEl);
});


this.addHeading('Style settings', 'lucide-external-link')
Expand Down
2 changes: 2 additions & 0 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ interface AnnotationElement {
subtype: string;
id: string;
rect: Rect;
inReplyTo?: string;
replyType?: 'R' | 'Group';
[key: string]: any;
}
}
Expand Down

0 comments on commit 87497f8

Please sign in to comment.