Skip to content

Commit

Permalink
release: 0.6.0 (canvas support)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Dec 31, 2023
1 parent 1f2abae commit a744354
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This [Obsidian.md](https://obsidian.md) plugin adds a ***quick preview*** functi
- [Link suggestions](https://help.obsidian.md/Linking+notes+and+files/Internal+links),
- [Quick switcher](https://help.obsidian.md/Plugins/Quick+switcher),
- and even [Quick switcher++](https://github.com/darlal/obsidian-switcher-plus).
- ***New in 0.6.0***: Canvas's note/media suggestion is now supported as well!

Hold down `Alt`/`Option` (by default) to quickly preview a suggestion before actually selecting it.

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": "quick-preview",
"name": "Quick Preview",
"version": "0.5.11",
"version": "0.6.0",
"minAppVersion": "1.3.5",
"description": "Quickly preview a suggestion before selecting it in link suggestions & quick switcher.",
"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-quick-preview",
"version": "0.5.11",
"version": "0.6.0",
"description": "An Obsidian.md plugin to quickly preview a suggestion before selecting it in link suggestions & quick swicher.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
27 changes: 26 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stripHeadingForLink } from 'obsidian';
import { stripHeadingForLink, SuggestModal } from 'obsidian';
import { HoverParent, Keymap, Plugin, UserEvent } from 'obsidian';
import { around } from 'monkey-around';

Expand Down Expand Up @@ -52,6 +52,7 @@ export default class QuickPreviewPlugin extends Plugin {
return info;
}
);
this.patchCanvasSuggest();
});
}

Expand Down Expand Up @@ -123,4 +124,28 @@ export default class QuickPreviewPlugin extends Plugin {

return uninstaller;
}

patchCanvasSuggest() {
const plugin = this;

const uninstaller = around(SuggestModal.prototype, {
setInstructions(old) {
return function (...args: any[]) {
old.call(this, ...args);
const proto = Object.getPrototypeOf(this);

if (this.hasOwnProperty('canvas') && proto.hasOwnProperty('showMarkdownAndCanvas') && proto.hasOwnProperty('showAttachments')) {
plugin.patchSuggester(this.constructor, (item: QuickSwitcherItem): PreviewInfo | null => {
if (!item.file) return null;
return { linktext: item.file.path, sourcePath: '' }
});

uninstaller();
}
}
}
});

this.register(uninstaller);
}
}

0 comments on commit a744354

Please sign in to comment.