generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
36 lines (31 loc) · 1016 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
const checkboxRegex = /((?:\n|^)\s*)- \[.\]/g;
export default class MyPlugin extends Plugin {
private _uncheckAll() {
const activeLeaf = this.app.workspace.activeLeaf;
if (activeLeaf?.view instanceof MarkdownView) {
const editor = activeLeaf.view.editor;
const doc = editor.getDoc();
const cursorPosition = doc.getCursor();
const entireContent = doc.getValue();
const updatedContent = entireContent.replace(checkboxRegex, "$1- [ ]");
doc.setValue(updatedContent);
doc.setCursor(cursorPosition);
}
}
async onload() {
// This adds a simple command that can be triggered anywhere
this.addCommand({
id: 'uncheck-all',
name: 'Uncheck All Checkboxes in File',
callback: () => {
this._uncheckAll();
},
editorCallback: (editor: Editor, view: MarkdownView) => {
this._uncheckAll();
},
});
}
onunload() {
}
}