Skip to content

Commit

Permalink
0.1.3
Browse files Browse the repository at this point in the history
- Fixed bug whereby dropping multiple files would not always trigger
open.
- Added Ctrl-key support for right-click menu item.
  • Loading branch information
jglev committed Jun 22, 2022
1 parent 51b0382 commit 6a9f565
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
22 changes: 15 additions & 7 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ interface FileWithPath extends File {
const handleFilesWithModal = (
plugin: RedirectPlugin,
app: App,
files: FileWithPath[] | TFile[]
files: FileWithPath[] | TFile[],
ctrlKey: boolean
) => {
const redirectFiles = getRedirectFiles(plugin, app.vault.getFiles());

const f = files[0];

[...files].forEach((f: FileWithPath | TFile) => {
let filePath = f.path;

Expand Down Expand Up @@ -224,12 +227,12 @@ const handleFilesWithModal = (
relevantRedirectFilesChunked.length === 1
) {
plugin.app.workspace
.getLeaf(false)
.getLeaf(ctrlKey)
.openFile(relevantRedirectFiles[0].originTFile);
return;
}

if (relevantRedirectFilesChunked.length > 1) {
if (relevantRedirectFilesChunked.length >= 1) {
const fileModal = new FilePathModal({
app: plugin.app,
fileOpener: true,
Expand Down Expand Up @@ -263,7 +266,7 @@ export default class RedirectPlugin extends Plugin {
this.app.workspace.on(
// @ts-ignore
"editor-drop",
async (evt: ClipboardEvent, editor: Editor) => {
async (evt: DragEvent, editor: Editor) => {
// Per https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts#L3690,
// "Check for `evt.defaultPrevented` before attempting to handle this
// event, and return if it has been already handled."
Expand All @@ -290,7 +293,7 @@ export default class RedirectPlugin extends Plugin {
(f: FileWithPath) => f.path.startsWith(basePath)
);

handleFilesWithModal(this, app, files);
handleFilesWithModal(this, app, files, evt.ctrlKey);
}
);

Expand Down Expand Up @@ -405,8 +408,13 @@ export default class RedirectPlugin extends Plugin {
menu.addItem((item) => {
item.setTitle("Open redirect origin file")
.setIcon("right-arrow-with-tail")
.onClick((e) => {
handleFilesWithModal(this, app, [file]);
.onClick((e: MouseEvent) => {
handleFilesWithModal(
this,
app,
[file],
e.ctrlKey
);
});
});
}
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": "obsidian-redirect",
"name": "Redirect",
"version": "0.1.2",
"version": "0.1.3",
"minAppVersion": "0.14.15",
"description": "An Obsidian (https://obsidian.md) plugin for redirecting links based on YAML frontmatter.",
"author": "Jacob Levernier",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-redirect",
"version": "0.1.2",
"version": "0.1.3",
"description": "An Obsidian (https://obsidian.md) plugin for redirecting links based on YAML frontmatter.",
"main": "main.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"0.1.0": "0.14.15",
"0.1.1": "0.14.15",
"0.1.2": "0.14.15"
"0.1.2": "0.14.15",
"0.1.3": "0.14.15"
}

0 comments on commit 6a9f565

Please sign in to comment.