generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.ts
54 lines (51 loc) · 1.43 KB
/
commands.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Notice, type Command } from "obsidian";
import { Settings } from "./settings";
import type { UnsafeApp } from "./types";
import { Operator } from "./operations";
export function createCommands(app: UnsafeApp, settings: Settings): Command[] {
return [
{
id: "dataview-publisher-insert-block",
name: "Insert dataview publish block",
editorCallback: (editor) => {
const { line, ch } = editor.getCursor();
const lineContent = editor.getLine(line);
try {
editor.replaceRange(
`
%% DATAVIEW_PUBLISHER: start
\`\`\`dataview
\`\`\`
%%
%% DATAVIEW_PUBLISHER: end %%`,
{
line,
ch: lineContent.length,
}
);
editor.setCursor(line, ch);
} catch (e) {
new Notice(e.message);
}
},
},
{
id: "dataview-publisher-update-blocks",
name: "Update dataview publish blocks",
callback: () => {
const operator = new Operator(app);
operator.updateFromSource(settings.source);
},
},
{
id: "dataview-publisher-update-blocks-and-publish",
name: "Update dataview publish blocks and open publish panel",
callback: () => {
const operator = new Operator(app);
operator.updateFromSource(settings.source);
// Open Obsidian Publish
app.commands.executeCommandById("publish:view-changes");
},
},
];
}