mirror of
https://github.com/idanlib/ObsidianFastForwardLinkPlugin.git
synced 2026-07-22 11:30:28 +00:00
Merge pull request #13 from IdanLib/fixing-event-handler-registration
Adding command to paste redirect syntax
This commit is contained in:
commit
93e48eb95a
1 changed files with 24 additions and 4 deletions
28
main.ts
28
main.ts
|
|
@ -14,6 +14,9 @@ const DEFAULT_SETTINGS: RedirectSettings = {
|
|||
export default class RedirectPlugin extends Plugin {
|
||||
settings: RedirectSettings;
|
||||
redirectsFolder: TFolder | null;
|
||||
redirectRef = async () => {
|
||||
await this.redirect();
|
||||
};
|
||||
|
||||
async changeSettings(newTab: boolean, switchToTab: boolean): Promise<void> {
|
||||
this.settings.openInNewTab = newTab;
|
||||
|
|
@ -93,8 +96,12 @@ export default class RedirectPlugin extends Plugin {
|
|||
);
|
||||
|
||||
if (!targetNoteFile) {
|
||||
new Notice(
|
||||
"Target note not found. Create one and try again.",
|
||||
3500
|
||||
);
|
||||
console.error(
|
||||
`No target note file found for target: ${targetNoteName}`
|
||||
`No target note file found for target: ${targetNoteName}. You can create one manually and try again.`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
|
@ -129,11 +136,16 @@ export default class RedirectPlugin extends Plugin {
|
|||
return;
|
||||
}
|
||||
|
||||
// Turn off event handler to avoid opening the target note twice
|
||||
this.app.workspace.off("file-open", this.redirectRef);
|
||||
|
||||
await this.app.workspace.openLinkText(
|
||||
redirectingNoteInFolder.name,
|
||||
redirectingNoteInFolder.path
|
||||
);
|
||||
|
||||
this.app.workspace.on("file-open", this.redirectRef);
|
||||
|
||||
return redirectingNoteInFolder;
|
||||
}
|
||||
}
|
||||
|
|
@ -179,13 +191,21 @@ export default class RedirectPlugin extends Plugin {
|
|||
await this.redirect();
|
||||
});
|
||||
|
||||
this.app.workspace.on("file-open", async (leaf) => {
|
||||
await this.redirect();
|
||||
this.app.workspace.on("file-open", this.redirectRef);
|
||||
|
||||
this.addCommand({
|
||||
id: "paste-redirect-syntax",
|
||||
name: "Paste Redirect Syntax onto Selection",
|
||||
hotkeys: [{ key: "r", modifiers: ["Ctrl", "Alt"] }],
|
||||
editorCallback: (editor, view) => {
|
||||
const selection = editor.getSelection();
|
||||
editor.replaceSelection(`::>[[${selection}]]`);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {
|
||||
this.app.workspace.off("file-open", this.redirect);
|
||||
this.app.workspace.off("file-open", this.redirectRef);
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue