Skip to content

Commit

Permalink
release: 0.40.21
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Jan 1, 2025
1 parent f10c286 commit 24ee96b
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.40.20",
"version": "0.40.21",
"minAppVersion": "1.5.8",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.40.20",
"version": "0.40.21",
"minAppVersion": "1.5.8",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-pdf-plus",
"version": "0.40.20",
"version": "0.40.21",
"description": "The most Obsidian-native PDF annotation tool ever.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/copy-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
const endOffset = getOffsetInTextLayerNode(endTextLayerNode, range.endContainer, range.endOffset);
if (beginIndex !== undefined && endIndex !== undefined && beginOffset !== null && endOffset !== null)
return {
beginIndex: +beginIndex,
beginIndex: +beginIndex - this.plugin.textDivFirstIdx,
beginOffset,
endIndex: +endIndex,
endIndex: +endIndex - this.plugin.textDivFirstIdx,
endOffset
};
}
Expand Down
17 changes: 12 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class PDFPlus extends Plugin {
pdfViewerChildren: Map<HTMLElement, PDFViewerChild> = new Map();
/** Stores all the shown context menu objects. Used to close all visible menus programatically. */
shownMenus: Set<Menu> = new Set();
textDivFirstIdx: number;
isDebugMode: boolean = false;

async onload() {
Expand Down Expand Up @@ -142,10 +143,10 @@ export default class PDFPlus extends Plugin {
}

checkVersion() {
const untestedVersion = '1.8.0';
if (requireApiVersion(untestedVersion)) {
console.warn(`${this.manifest.name}: This plugin has not been tested on Obsidian ${untestedVersion} or above. Please report any issue you encounter on GitHub (https://github.com/RyotaUshio/obsidian-pdf-plus/issues/new/choose).`);
}
// See:
// https://forum.obsidian.md/t/in-1-8-0-pdf-copy-link-to-selection-fails-to-copy-proper-links-in-some-cases/93545
// https://github.com/RyotaUshio/obsidian-pdf-plus/issues/327
this.textDivFirstIdx = requireApiVersion('1.8.0') ? 1 : 0;

InstallerVersionModal.openIfNecessary(this);
}
Expand Down Expand Up @@ -733,7 +734,13 @@ export default class PDFPlus extends Plugin {

openSettingTab(): PDFPlusSettingTab {
this.app.setting.open();
return this.app.setting.openTabById(this.manifest.id);
// This `if` check is necessary. If we omit it, the following bug occurs:
// https://github.com/RyotaUshio/obsidian-pdf-plus/issues/309
// I learned this from the core Sync plugin's `openSettings` method.
if (this.app.setting.activeTab !== this.settingTab) {
this.app.setting.openTabById(this.manifest.id);
}
return this.settingTab;
}

openHotkeySettingTab(query?: string): SettingTab {
Expand Down
12 changes: 12 additions & 0 deletions src/patchers/pdf-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,18 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => {
return embedLink.slice(1);
};
},
getTextSelectionRangeStr() {
return function (this: PDFViewerChild, pageEl: HTMLElement) {
const selection = pageEl.win.getSelection();
const range = (selection && selection.rangeCount > 0) ? selection.getRangeAt(0) : null;
const textSelectionRange = range && lib.copyLink.getTextSelectionRange(pageEl, range);
if (textSelectionRange) {
const { beginIndex, beginOffset, endIndex, endOffset } = textSelectionRange;
return `${beginIndex},${beginOffset},${endIndex},${endOffset}`;
}
return null;
};
},
getPageLinkAlias(old) {
return function (this: PDFViewerChild, page: number): string {
if (this.file) {
Expand Down
17 changes: 16 additions & 1 deletion src/post-process/pdf-link-like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class PDFLinkLikePostProcessor implements HoverParent {
set hoverPopover(hoverPopover) {
this.child.hoverPopover = hoverPopover;
if (hoverPopover) {
hoverPopover.hoverEl.addClass('pdf-plus-pdf-link-like-popover');
this.onHoverPopoverSet(hoverPopover);
}
}
Expand Down Expand Up @@ -183,7 +184,6 @@ abstract class PDFDestinationHolderPostProcessor extends PDFLinkLikePostProcesso

onHoverPopoverSet(hoverPopover: HoverPopover): void {
const el = hoverPopover.hoverEl;
el.addClass('pdf-plus-pdf-internal-link-popover');
const dest = this.getDest();
if (typeof dest === 'string') el.dataset.dest = dest;
}
Expand Down Expand Up @@ -266,6 +266,11 @@ export class PDFInternalLinkPostProcessor extends PDFDestinationHolderPostProces

return false;
}

onHoverPopoverSet(hoverPopover: HoverPopover): void {
super.onHoverPopoverSet(hoverPopover);
hoverPopover.hoverEl.addClass('pdf-plus-pdf-internal-link-popover');
}
}


Expand Down Expand Up @@ -299,6 +304,11 @@ export class PDFOutlineItemPostProcessor extends PDFDestinationHolderPostProcess
return this.plugin.settings.recordHistoryOnOutlineClick
&& !this.child.opts.isEmbed;
}

onHoverPopoverSet(hoverPopover: HoverPopover): void {
super.onHoverPopoverSet(hoverPopover);
hoverPopover.hoverEl.addClass('pdf-plus-outline-item-popover');
}
}


Expand Down Expand Up @@ -328,4 +338,9 @@ export class PDFThumbnailItemPostProcessor extends PDFLinkLikePostProcessor {
return this.plugin.settings.recordHistoryOnThumbnailClick
&& !this.child.opts.isEmbed;
}

onHoverPopoverSet(hoverPopover: HoverPopover): void {
super.onHoverPopoverSet(hoverPopover);
hoverPopover.hoverEl.addClass('pdf-plus-thumbnail-item-popover');
}
}
3 changes: 2 additions & 1 deletion src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ interface PDFViewerChild {
getTextByRect(pageView: PDFPageView, rect: Rect): string;
getAnnotationFromEvt(pageView: PDFPageView, evt: MouseEvent): AnnotationElement | null;
getPageLinkAlias(page: number): string;
getTextSelectionRangeStr(el: HTMLElement): string;
getTextSelectionRangeStr(pageEl: HTMLElement): string | null;
getMarkdownLink(subpath?: string, alias?: string, embed?: boolean): string;
onContextMenu(evt: MouseEvent): void;
/** On mobile, tapping on "Copy" in the the OS-provided menu calls this method, in which, in the original implementation, performs "Copy as quote". */
Expand Down Expand Up @@ -812,6 +812,7 @@ interface Queue {
interface AppSetting extends Modal {
openTab(tab: SettingTab): void;
openTabById(id: string): any;
activeTab: SettingTab | null;
pluginTabs: PluginSettingTab[];
}

Expand Down
7 changes: 6 additions & 1 deletion src/vim/text-structure-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export class PDFDocumentTextStructureParser extends PDFPlusComponent {
}


export type PDFTextPos = { index: number, offset: number };
export type PDFTextPos = {
/** The 0-origin index of the text layer node containing this position. */
index: number;
/** The offset of this position within the text layer node. */
offset: number;
};


export class PDFPageTextStructureParser {
Expand Down
2 changes: 1 addition & 1 deletion src/vim/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class VimVisualMode extends VimBindingsMode {
}
}

return { index, offset };
return { index: index - this.plugin.textDivFirstIdx, offset };
}

extendSelection(getNewHeadPos: (state: { currentHeadPos: PDFTextPos, pageNumber: number, pageParser: PDFPageTextStructureParser }) => PDFTextPos | null) {
Expand Down
31 changes: 30 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ settings:
-
id: pdf-plus-backlink-popover
title: Backlink popovers
description: Style for popovers displayed when hovering over backlinked highlights or rectangular selections in PDF viewer
description: Styles for popovers displayed when hovering over backlinked highlights or rectangular selections in PDF viewer
type: heading
level: 3
-
Expand All @@ -87,6 +87,30 @@ settings:
step: 10
default: 400
format: px
-
id: pdf-plus-pdf-link-like-popover
title: PDF internal link popovers
description: Styles for popovers displayed when hovering over internal links, outline items or thumbnails in PDF viewer
type: heading
level: 3
-
id: pdf-plus-pdf-link-like-popover-width
title: PDF internal link popover width (px)
type: variable-number-slider
min: 100
max: 1000
step: 10
default: 450
format: px
-
id: pdf-plus-pdf-link-like-popover-height
title: PDF internal link popover height (px)
type: variable-number-slider
min: 100
max: 1000
step: 10
default: 400
format: px
-
id: pdf-toolbar
title: PDF toolbars
Expand Down Expand Up @@ -560,6 +584,11 @@ body {
--popover-height: var(--pdf-plus-backlink-popover-height, 400px);
}

.popover.hover-popover.pdf-plus-pdf-link-like-popover {
--popover-pdf-width: var(--pdf-plus-pdf-link-like-popover-width, 450px);
--popover-pdf-height: var(--pdf-plus-pdf-link-like-popover-height, 400px);
}

.popover.hover-popover.pdf-plus-bib-popover {
--popover-width: 400px;
--pdf-plus-bib-metadata-font-size: var(--font-ui-small);
Expand Down

0 comments on commit 24ee96b

Please sign in to comment.