Skip to content

Commit

Permalink
release: 0.40.10
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Sep 23, 2024
1 parent 127ea5b commit b7bc9e4
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 241 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.9",
"version": "0.40.10",
"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.9",
"version": "0.40.10",
"minAppVersion": "1.5.8",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
229 changes: 112 additions & 117 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-pdf-plus",
"version": "0.40.9",
"version": "0.40.10",
"description": "The most Obsidian-native PDF annotation tool ever.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand All @@ -11,16 +11,16 @@
"author": "Ryota Ushio",
"license": "MIT",
"devDependencies": {
"@cantoo/pdf-lib": "^1.21.0",
"@types/node": "^16.18.96",
"@cantoo/pdf-lib": "^1.21.1",
"@types/node": "^16.18.108",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"electron": "^28.3.1",
"electron": "^28.3.3",
"esbuild": "0.17.3",
"monkey-around": "^3.0.0",
"obsidian": "^1.5.7",
"pdfjs-dist": "^4.2.67",
"obsidian": "^1.7.2",
"pdfjs-dist": "^4.6.82",
"tslib": "2.4.0",
"typescript": "4.7.4"
}
Expand Down
4 changes: 2 additions & 2 deletions src/bib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ export class BibliographyManager extends PDFPlusComponent {

on(name: 'extracted', callback: (destId: string, bibText: string) => any, ctx?: any): ReturnType<Events['on']>;
on(name: 'parsed', callback: (destId: string, parsedBib: string) => any, ctx?: any): ReturnType<Events['on']>;
on(...args: Parameters<Events['on']>) {
return this.events.on(...args);
on(name: string, callback: (...args: any[]) => any, ctx?: any) {
return this.events.on(name, callback, ctx);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export const onOutlineItemContextMenu = (plugin: PDFPlus, child: PDFViewerChild,
if (settings.openAfterExtractPages) {
const leaf = lib.workspace.getLeaf(settings.howToOpenExtractedPDF);
await leaf.openFile(file);
lib.workspace.revealLeaf(leaf);
await lib.workspace.revealLeaf(leaf);
}
});
});
Expand Down
8 changes: 5 additions & 3 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ export class PDFPlusCommands extends PDFPlusLibSubmodule {
if (this.settings.openAfterExtractPages) {
const leaf = this.lib.workspace.getLeaf(this.settings.howToOpenExtractedPDF);
await leaf.openFile(file);
this.lib.workspace.revealLeaf(leaf);
await this.lib.workspace.revealLeaf(leaf);
}
});
});
Expand Down Expand Up @@ -669,7 +669,7 @@ export class PDFPlusCommands extends PDFPlusLibSubmodule {
if (this.settings.openAfterExtractPages) {
const leaf = this.lib.workspace.getLeaf(this.settings.howToOpenExtractedPDF);
await leaf.openFile(file);
this.lib.workspace.revealLeaf(leaf);
await this.lib.workspace.revealLeaf(leaf);
}
});
});
Expand Down Expand Up @@ -831,9 +831,11 @@ export class PDFPlusCommands extends PDFPlusLibSubmodule {
const openFile = async () => {
const { leaf, isExistingLeaf } = await this.lib.copyLink.prepareMarkdownLeafForPaste(file);
if (leaf) {
this.lib.workspace.revealLeaf(leaf);
await this.lib.workspace.revealLeaf(leaf);
this.app.workspace.setActiveLeaf(leaf);
const view = leaf.view;
// We don't have to care about the case where the view is a deferred view
// thanks to the awaited revealLeaf call above.
if (view instanceof MarkdownView) {
const editor = view.editor;
editor.focus();
Expand Down
24 changes: 18 additions & 6 deletions src/lib/copy-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
if (file) { // auto-focus target found
const { leaf, isExistingLeaf } = await this.prepareMarkdownLeafForPaste(file);
if (leaf && leaf.view instanceof MarkdownView) {
this.updateAndRevealCursorInEditor(leaf.view, {
await this.updateAndRevealCursorInEditor(leaf.view, {
focus: true,
goEnd: !isExistingLeaf
});
Expand Down Expand Up @@ -644,6 +644,10 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
return null;
}

/**
* Note that if this method returns a workspace leaf, its view IS guaranteed to be loaded
* (i.e. the view is not a detached view).
*/
async prepareMarkdownLeafForPaste(file: TFile) {
let leaf = this.lib.workspace.getExistingLeafForMarkdownFile(file);
const isExistingLeaf = !!leaf;
Expand All @@ -660,7 +664,12 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
}

if (leaf && this.settings.openAutoFocusTargetInEditingView) {
// The follwoing line should be unnecesary because this block is
// only executed when the leaf is newly created.
// But I'll put it here just in case.
await this.lib.workspace.ensureViewLoaded(leaf);
const view = leaf.view;

if (view instanceof MarkdownView) {
await view.setState({ mode: 'source' }, { history: false });
view.setEphemeralState({ focus: false });
Expand All @@ -669,6 +678,9 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
}

if (leaf) {
// GUARANTEE THAT THE VIEW IS LOADED
await this.lib.workspace.ensureViewLoaded(leaf);

this.lib.workspace.hoverEditor.postProcessHoverEditorLeaf(leaf);
if (this.settings.closeSidebarWhenLostFocus) {
this.lib.workspace.registerHideSidebar(leaf);
Expand Down Expand Up @@ -713,7 +725,7 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
// the backlink highlight will be visibile as soon as possible.
view.save();

this.updateAndRevealCursorInEditor(leaf.view, {
await this.updateAndRevealCursorInEditor(leaf.view, {
focus: this.settings.focusEditorAfterAutoPaste,
goEnd: !this.settings.respectCursorPositionWhenAutoPaste
});
Expand All @@ -731,9 +743,9 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
// When the file opened in some tab,
// - focus the tab and move the cursor to the end of the file if the `focusEditorAfterAutoPaste` option is on
// - scroll to the end of the file without focusing if `focusEditorAfterAutoPaste` option is off
activeWindow.setTimeout(() => {
activeWindow.setTimeout(async () => {
if (leaf.view instanceof MarkdownView) {
this.updateAndRevealCursorInEditor(leaf.view, {
await this.updateAndRevealCursorInEditor(leaf.view, {
focus: this.settings.focusEditorAfterAutoPaste,
goEnd: true
});
Expand All @@ -743,15 +755,15 @@ export class copyLinkLib extends PDFPlusLibSubmodule {
}
}

updateAndRevealCursorInEditor(view: MarkdownView, options: { focus: boolean, goEnd: boolean }) {
async updateAndRevealCursorInEditor(view: MarkdownView, options: { focus: boolean, goEnd: boolean }) {
const { focus, goEnd } = options;

const editor = view.editor;

if (focus) {
if (goEnd) editor.exec('goEnd');

this.lib.workspace.revealLeaf(view.leaf);
await this.lib.workspace.revealLeaf(view.leaf);
this.app.workspace.setActiveLeaf(view.leaf);
editor.focus();
}
Expand Down
12 changes: 10 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Component, EditableFileView, MarkdownView, Notice, Platform, TFile, TextFileView, View, base64ToArrayBuffer, normalizePath, parseLinktext, requestUrl } from 'obsidian';
import { App, Component, EditableFileView, FileView, MarkdownView, Notice, Platform, TFile, TextFileView, View, base64ToArrayBuffer, normalizePath, parseLinktext, requestUrl } from 'obsidian';
import { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
import { EncryptedPDFError, PDFArray, PDFDict, PDFDocument, PDFName, PDFNumber, PDFRef } from '@cantoo/pdf-lib';

Expand All @@ -14,7 +14,7 @@ import { PDFOutlines } from './outlines';
import { NameTree, NumberTree } from './name-or-number-trees';
import { PDFNamedDestinations } from './destinations';
import { PDFPageLabels } from './page-labels';
import { AnnotationElement, CanvasFileNode, CanvasNode, CanvasView, DestArray, EventBus, ObsidianViewer, PDFPageView, PDFView, PDFViewExtraState, PDFViewerChild, PDFJsDestArray, PDFViewer, PDFEmbed, PDFViewState, Rect, TextContentItem, PDFFindBar, PDFSearchSettings, PDFJsEventMap } from 'typings';
import { AnnotationElement, CanvasFileNode, CanvasNode, CanvasView, DestArray, EventBus, ObsidianViewer, PDFPageView, PDFView, PDFViewExtraState, PDFViewerChild, PDFJsDestArray, PDFViewer, PDFEmbed, PDFViewState, Rect, TextContentItem, PDFFindBar, PDFSearchSettings, PDFJsEventMap, BacklinkView } from 'typings';
import { PDFCroppedEmbed } from 'pdf-cropped-embed';
import { PDFBacklinkIndex } from './pdf-backlink-index';
import { Speech } from './speech';
Expand Down Expand Up @@ -606,6 +606,7 @@ export class PDFPlusLib {

const view = leaf.view;

// We should not use view.getViewType() here because it cannot detect deferred views.
if (view instanceof MarkdownView) {
pdfEmbed = this.getPDFEmbedInMarkdownView(view);
} else if (this.isCanvasView(view)) {
Expand Down Expand Up @@ -798,6 +799,7 @@ export class PDFPlusLib {
if (this.plugin.classes.PDFView) {
return view instanceof this.plugin.classes.PDFView;
}
// The instanceof check is necessary for correctly handling DeferredView.
return view instanceof EditableFileView && view.getViewType() === 'pdf';
}

Expand All @@ -814,6 +816,7 @@ export class PDFPlusLib {
}

isCanvasView(view: View): view is CanvasView {
// The instanceof check is necessary for correctly handling DeferredView.
return view instanceof TextFileView && view.getViewType() === 'canvas' && 'canvas' in view
}

Expand All @@ -828,6 +831,11 @@ export class PDFPlusLib {
return false;
}

isBacklinkView(view: View): view is BacklinkView {
// The instanceof check is necessary for correctly handling DeferredView.
return view instanceof FileView && view.getViewType() === 'backlink';
}

getAvailablePathForCopy(file: TFile) {
return this.app.vault.getAvailablePath(removeExtension(file.path), file.extension)
}
Expand Down
Loading

0 comments on commit b7bc9e4

Please sign in to comment.