Skip to content

Commit 26a2266

Browse files
Add new commands for deleting current line and undoing last edit
1 parent 6895589 commit 26a2266

File tree

1 file changed

+104
-85
lines changed

1 file changed

+104
-85
lines changed

src/mainParts/addCommands.ts

Lines changed: 104 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,111 @@
1-
import { Plugin } from "obsidian";
1+
import { Editor, MarkdownView, Plugin } from "obsidian";
22
import familyModal from "../createFamily/familyModal";
33
import { createClustersAndOrphansFolder } from "../createFamily/createClustersAndOrphansFolder";
4-
import { NewFileLocation } from '../util/U';
4+
import { NewFileLocation } from "../util/U";
55
import deleteActiveNoteModal from "src/createFamily/deleteActiveNoteModal";
66
import SimpleFocusClass from "src/focus/simpleFocus";
77
const SimpleFocus = new SimpleFocusClass();
88

9-
109
export function addCommands(plugin: Plugin) {
11-
plugin.addCommand({
12-
id: "New-Cluster",
13-
name: "new cluster",
14-
callback: () => {
15-
createClustersAndOrphansFolder(plugin.app);
16-
new familyModal(
17-
plugin.app,
18-
NewFileLocation.NewTab,
19-
"newCluster",
20-
undefined,
21-
).open();
22-
},
23-
});
24-
plugin.addCommand({
25-
id: "New-Child",
26-
name: "New child",
27-
callback: () => {
28-
createClustersAndOrphansFolder(plugin.app);
29-
new familyModal(
30-
plugin.app,
31-
NewFileLocation.NewTab,
32-
"newChild",
33-
undefined,
34-
).open();
35-
},
36-
});
37-
plugin.addCommand({
38-
id: "New-Sibling",
39-
name: "New sibling",
40-
callback: () => {
41-
createClustersAndOrphansFolder(plugin.app);
42-
new familyModal(
43-
plugin.app,
44-
NewFileLocation.NewTab,
45-
"newSibling",
46-
undefined,
47-
).open();
48-
},
49-
});
50-
plugin.addCommand({
51-
id: "New-Orphan",
52-
name: "New orphan",
53-
callback: () => {
54-
createClustersAndOrphansFolder(plugin.app);
55-
new familyModal(
56-
plugin.app,
57-
NewFileLocation.NewTab,
58-
"newOrphan",
59-
undefined,
60-
).open();
61-
},
62-
});
63-
plugin.addCommand({
64-
id: "Delete-Active-Note",
65-
name: "Delete active note",
66-
callback: () => {
67-
createClustersAndOrphansFolder(plugin.app);
68-
new deleteActiveNoteModal(
69-
plugin.app,
70-
NewFileLocation.NewTab,
71-
"deleteNote",
72-
).open();
73-
},
74-
});
75-
plugin.addCommand({
76-
id: "simple-focus-exit-focus",
77-
name: "Exit focus",
78-
callback: () => {
79-
SimpleFocus.exitFocus()
80-
},
81-
});
82-
plugin.addCommand({
83-
id: "simple-focus-enter-focus",
84-
name: "Enter focus",
85-
callback: () => {
86-
const file = plugin.app.workspace.getActiveFile();
87-
if (file?.path) {
88-
SimpleFocus.enterFocus(file.path)
89-
}
90-
},
91-
});
92-
}
10+
plugin.addCommand({
11+
id: "New-Cluster",
12+
name: "new cluster",
13+
callback: () => {
14+
createClustersAndOrphansFolder(plugin.app);
15+
new familyModal(
16+
plugin.app,
17+
NewFileLocation.NewTab,
18+
"newCluster",
19+
undefined,
20+
).open();
21+
},
22+
});
23+
plugin.addCommand({
24+
id: "New-Child",
25+
name: "New child",
26+
callback: () => {
27+
createClustersAndOrphansFolder(plugin.app);
28+
new familyModal(
29+
plugin.app,
30+
NewFileLocation.NewTab,
31+
"newChild",
32+
undefined,
33+
).open();
34+
},
35+
});
36+
plugin.addCommand({
37+
id: "New-Sibling",
38+
name: "New sibling",
39+
callback: () => {
40+
createClustersAndOrphansFolder(plugin.app);
41+
new familyModal(
42+
plugin.app,
43+
NewFileLocation.NewTab,
44+
"newSibling",
45+
undefined,
46+
).open();
47+
},
48+
});
49+
plugin.addCommand({
50+
id: "New-Orphan",
51+
name: "New orphan",
52+
callback: () => {
53+
createClustersAndOrphansFolder(plugin.app);
54+
new familyModal(
55+
plugin.app,
56+
NewFileLocation.NewTab,
57+
"newOrphan",
58+
undefined,
59+
).open();
60+
},
61+
});
62+
plugin.addCommand({
63+
id: "Delete-Active-Note",
64+
name: "Delete active note",
65+
callback: () => {
66+
createClustersAndOrphansFolder(plugin.app);
67+
new deleteActiveNoteModal(
68+
plugin.app,
69+
NewFileLocation.NewTab,
70+
"deleteNote",
71+
).open();
72+
},
73+
});
74+
plugin.addCommand({
75+
id: "simple-focus-exit-focus",
76+
name: "Exit focus",
77+
callback: () => {
78+
SimpleFocus.exitFocus();
79+
},
80+
});
81+
plugin.addCommand({
82+
id: "simple-focus-enter-focus",
83+
name: "Enter focus",
84+
callback: () => {
85+
const file = plugin.app.workspace.getActiveFile();
86+
if (file?.path) {
87+
SimpleFocus.enterFocus(file.path);
88+
}
89+
},
90+
});
91+
plugin.addCommand({
92+
id: "delete-current-line",
93+
name: "Delete current line",
94+
callback: () => {
95+
const view = plugin.app.workspace.getActiveViewOfType(MarkdownView);
96+
const editor = view?.editor as Editor;
97+
editor.exec("deleteLine");
98+
editor.focus();
99+
},
100+
});
101+
plugin.addCommand({
102+
id: "undo-last-edit",
103+
name: "Undo last edit",
104+
callback: () => {
105+
const view = plugin.app.workspace.getActiveViewOfType(MarkdownView);
106+
const editor = view?.editor as Editor;
107+
editor.undo();
108+
editor.focus();
109+
},
110+
});
111+
}

0 commit comments

Comments
 (0)