|
1 | | -import { Editor } from "obsidian"; |
| 1 | +import { Editor, MarkdownView } from "obsidian"; |
2 | 2 | import { DiscourseNode } from "~/types"; |
3 | | -import { createDiscourseNode } from "~/utils/createNode"; |
4 | 3 | import type DiscourseGraphPlugin from "~/index"; |
| 4 | +import { createModifyNodeModalSubmitHandler } from "~/utils/registerCommands"; |
| 5 | +import ModifyNodeModal from "./ModifyNodeModal"; |
5 | 6 |
|
6 | 7 | /** |
7 | 8 | * A popover that shows all node types inline near the cursor/selection. |
@@ -98,7 +99,7 @@ export class InlineNodeTypePicker { |
98 | 99 | itemEl.addEventListener("mousedown", (e) => { |
99 | 100 | e.preventDefault(); |
100 | 101 | e.stopPropagation(); |
101 | | - void this.selectItem(item); |
| 102 | + this.selectItem(item); |
102 | 103 | }); |
103 | 104 |
|
104 | 105 | itemEl.addEventListener("mouseenter", () => { |
@@ -138,14 +139,22 @@ export class InlineNodeTypePicker { |
138 | 139 | } |
139 | 140 | } |
140 | 141 |
|
141 | | - private async selectItem(item: DiscourseNode) { |
| 142 | + private selectItem(item: DiscourseNode) { |
142 | 143 | this.close(); |
143 | | - await createDiscourseNode({ |
| 144 | + const currentFile = |
| 145 | + this.options.plugin.app.workspace.getActiveViewOfType(MarkdownView) |
| 146 | + ?.file || undefined; |
| 147 | + new ModifyNodeModal(this.options.plugin.app, { |
| 148 | + nodeTypes: this.options.plugin.settings.nodeTypes, |
144 | 149 | plugin: this.options.plugin, |
145 | | - nodeType: item, |
146 | | - text: this.options.selectedText, |
147 | | - editor: this.options.editor, |
148 | | - }); |
| 150 | + initialTitle: this.options.selectedText, |
| 151 | + initialNodeType: item, |
| 152 | + currentFile, |
| 153 | + onSubmit: createModifyNodeModalSubmitHandler( |
| 154 | + this.options.plugin, |
| 155 | + this.options.editor, |
| 156 | + ), |
| 157 | + }).open(); |
149 | 158 | } |
150 | 159 |
|
151 | 160 | private setupEventHandlers() { |
@@ -173,7 +182,7 @@ export class InlineNodeTypePicker { |
173 | 182 | e.stopPropagation(); |
174 | 183 | const selectedItem = this.items[this.selectedIndex]; |
175 | 184 | if (selectedItem) { |
176 | | - void this.selectItem(selectedItem); |
| 185 | + this.selectItem(selectedItem); |
177 | 186 | } |
178 | 187 | } else if (e.key === "Escape") { |
179 | 188 | e.preventDefault(); |
|
0 commit comments