Skip to content

Commit

Permalink
Merge pull request #33 from NomarCub/obsidian-1.5-update
Browse files Browse the repository at this point in the history
Obsidian 1.5 update
  • Loading branch information
NomarCub authored Jan 3, 2024
2 parents 71452fe + 9aadb1f commit 227de9d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ This plugin context the following context menus

in reading view in [Obsidian](https://obsidian.md/).

This makes copying URLs in reading view like it is in editing view by deafult. For copying images in edit mode check out [Ozan's Image in Editor Plugin](https://github.com/ozntel/oz-image-in-editor-obsidian)
This makes copying URLs in reading view like it is in editing view by deafult.

See these other plugins for related functionality:
- [Ozan's Image in Editor Plugin](https://github.com/ozntel/oz-image-in-editor-obsidian)
- [Image Toolkit](https://github.com/sissilab/obsidian-image-toolkit)

Copying images:

Expand All @@ -25,7 +29,7 @@ Opening PDFs externally:

![Opening PDFs externally on desktop](https://user-images.githubusercontent.com/5298006/171170626-5a94f5dc-61fc-4661-a9f2-38a0fb0181f5.gif)

All features work on mobile, but were only tested on Android:
All features work on mobile, but were only tested on Android. Mobile uses the native image sharing functionality instead of the clipboard, and it downloads online images temporarily so they can be shared.

![Copying URLs on Android](https://user-images.githubusercontent.com/5298006/125515758-bdf77074-a58c-4a6d-affa-88d031991ab2.gif)

Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "copy-url-in-preview",
"name": "Copy Image and URL context menu",
"version": "1.5.1",
"minAppVersion": "0.16.3",
"version": "1.5.2",
"minAppVersion": "1.4.11",
"description": "Copy Image, Copy URL and Open PDF externally context menu in reading view (formerly preview mode)",
"author": "NomarCub",
"authorUrl": "https://github.com/NomarCub",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copy-url-in-preview",
"version": "1.5.1",
"version": "1.5.2",
"description": "Copy Image, Copy URL and Open PDF externally context menu in reading view (formerly preview mode) for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand All @@ -18,7 +18,7 @@
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"eslint": "8.46.0",
"obsidian": "^0.16.3",
"obsidian": "^1.4.11",
"tslib": "2.4.0",
"typescript": "4.7.4"
}
Expand Down
17 changes: 8 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class CopyUrlInPreview extends Plugin {
await this.loadSettings();
this.addSettingTab(new CopyUrlInPreviewSettingTab(this.app, this));
this.registerDocument(document);
app.workspace.on("window-open",
this.app.workspace.on("window-open",
(workspaceWindow, window) => {
this.registerDocument(window.document);
});
Expand Down Expand Up @@ -122,7 +122,7 @@ export default class CopyUrlInPreview extends Plugin {
}

storeLastHoveredLinkInEditor(event: MouseEvent) {
const editor = app.workspace.getActiveViewOfType(MarkdownView)?.editor as EditorInternalApi;
const editor = this.app.workspace.getActiveViewOfType(MarkdownView)?.editor as EditorInternalApi;
if (!editor) {
return;
}
Expand Down Expand Up @@ -304,10 +304,9 @@ export default class CopyUrlInPreview extends Plugin {
})
);
if (protocol === "app:" && Platform.isDesktop) {
// href probably also works
// getResourcePath("") also works for root path
const baseFilePath = (app.vault.adapter as FileSystemAdapterWithInternalApi).getFilePath("");
const baseFilePathName: string = (baseFilePath as any).pathname;
const baseFilePath = (this.app.vault.adapter as FileSystemAdapterWithInternalApi).getFilePath("");
const baseFilePathName: string = baseFilePath.replace("file://", "");
const urlPathName: string = (url as any).pathname;
if (urlPathName.startsWith(baseFilePathName)) {
let relativePath = urlPathName.replace(baseFilePathName, "");
Expand All @@ -316,21 +315,21 @@ export default class CopyUrlInPreview extends Plugin {
menu.addItem((item: MenuItem) => item
.setIcon("arrow-up-right")
.setTitle("Open in default app")
.onClick(() => (app as AppWithDesktopInternalApi).openWithDefaultApp(relativePath))
.onClick(() => (this.app as AppWithDesktopInternalApi).openWithDefaultApp(relativePath))
);
menu.addItem((item: MenuItem) => item
.setIcon("arrow-up-right")
.setTitle(Platform.isMacOS ? "Reveal in finder" : "Show in system explorer")
.onClick(() => {
(app as AppWithDesktopInternalApi).showInFolder(relativePath);
(this.app as AppWithDesktopInternalApi).showInFolder(relativePath);
})
);
menu.addItem((item: MenuItem) => item
.setIcon("folder")
.setTitle("Reveal file in navigation")
.onClick(() => {
const abstractFilePath = app.vault.getAbstractFileByPath(relativePath.substring(1));
(app as any).internalPlugins.getEnabledPluginById("file-explorer").revealInFolder(abstractFilePath);
const abstractFilePath = this.app.vault.getAbstractFileByPath(relativePath.substring(1));
(this.app as any).internalPlugins.getEnabledPluginById("file-explorer").revealInFolder(abstractFilePath);
})
);
}
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"1.0.0": "0.11.13",
"1.3.2": "0.14.8",
"1.3.5": "0.15.4",
"1.4.0": "0.16.3"
"1.4.0": "0.16.3",
"1.5.2": "1.4.11"
}

0 comments on commit 227de9d

Please sign in to comment.