mirror of
https://github.com/lizard-heart/obsidian-to-omnifocus.git
synced 2026-07-22 07:30:26 +00:00
Merge pull request #5 from nweisenfeld/neil/fix-doubles
update markComplete to work with selection or whole document
This commit is contained in:
commit
f3d6b2d73a
1 changed files with 17 additions and 9 deletions
22
src/main.ts
22
src/main.ts
|
|
@ -26,8 +26,7 @@ export default class TasksToOmnifocus extends Plugin {
|
|||
id: 'extract-tasks',
|
||||
name: 'Extract Tasks Into OmniFocus',
|
||||
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||
const editorText = editor.getValue()
|
||||
this.addToOmnifocus(editorText, editor, view);
|
||||
this.addToOmnifocus(false, editor, view);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -35,15 +34,20 @@ export default class TasksToOmnifocus extends Plugin {
|
|||
id: 'extract-tasks-selection',
|
||||
name: 'Extract Tasks from selection Into OmniFocus',
|
||||
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||
const editorText = editor.getSelection();
|
||||
this.addToOmnifocus(editorText, editor, view);
|
||||
this.addToOmnifocus(true, editor, view);
|
||||
},
|
||||
});
|
||||
|
||||
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
|
||||
}
|
||||
|
||||
async addToOmnifocus(editorText: string, editor: Editor, view: MarkdownView) {
|
||||
async addToOmnifocus(isSelection: bool, editor: Editor, view: MarkdownView) {
|
||||
var editorText;
|
||||
if (isSelection) {
|
||||
editorText = editor.getSelection();
|
||||
} else {
|
||||
editorText = editor.getValue();
|
||||
}
|
||||
try {
|
||||
let tasks = editorText.match(/- \[ \] .*/g);
|
||||
|
||||
|
|
@ -61,7 +65,11 @@ export default class TasksToOmnifocus extends Plugin {
|
|||
|
||||
if (this.settings.markComplete) {
|
||||
let completedText = editorText.replace(/- \[ \]/g, "- [x]");
|
||||
editor.replaceSelection(completedText);
|
||||
if (isSelection) {
|
||||
editor.replaceSelection(completedText);
|
||||
} else {
|
||||
editor.setValue(completedText)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
|
@ -73,7 +81,7 @@ export default class TasksToOmnifocus extends Plugin {
|
|||
await this.saveData(this.settings);
|
||||
}
|
||||
|
||||
onunload() {}
|
||||
onunload() { }
|
||||
|
||||
|
||||
private async loadSettings() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue