Merge pull request #5 from nweisenfeld/neil/fix-doubles

update markComplete to work with selection or whole document
This commit is contained in:
Henry Gustafson 2023-05-31 15:52:49 -07:00 committed by GitHub
commit f3d6b2d73a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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]");
if (isSelection) {
editor.replaceSelection(completedText);
} else {
editor.setValue(completedText)
}
}
} catch (err) {