mirror of
https://github.com/lizard-heart/obsidian-to-omnifocus.git
synced 2026-07-22 07:30:26 +00:00
Merge pull request #2 from mattsmallman/main
Added - Extract Tasks from selection into Omnifocus Command
This commit is contained in:
commit
b7aecc8ad6
1 changed files with 31 additions and 0 deletions
31
src/main.ts
31
src/main.ts
|
|
@ -57,6 +57,37 @@ export default class TasksToOmnifocus extends Plugin {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.addCommand({
|
||||||
|
id: 'extract-tasks-selection',
|
||||||
|
name: 'Extract Tasks from selection Into OmniFocus',
|
||||||
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||||
|
const editorText = editor.getSelection()
|
||||||
|
try {
|
||||||
|
let tasks = editorText.match(/- \[ \] .*/g);
|
||||||
|
|
||||||
|
for (let task of tasks) {
|
||||||
|
let taskName = task.replace("- [ ] ", "");
|
||||||
|
let taskNameEncoded = encodeURIComponent(taskName);
|
||||||
|
let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
||||||
|
let vaultName = app.vault.getName();
|
||||||
|
let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL);
|
||||||
|
|
||||||
|
window.open(
|
||||||
|
`omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.settings.markComplete) {
|
||||||
|
let completedText = editorText.replace(/- \[ \]/g, "- [x]");
|
||||||
|
editor.replaceSelection(completedText);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
|
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue