Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions apps/obsidian/src/components/InlineNodeTypePicker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Editor } from "obsidian";
import { Editor, MarkdownView } from "obsidian";
import { DiscourseNode } from "~/types";
import { createDiscourseNode } from "~/utils/createNode";
import type DiscourseGraphPlugin from "~/index";
import { createModifyNodeModalSubmitHandler } from "~/utils/registerCommands";
import ModifyNodeModal from "./ModifyNodeModal";

/**
* A popover that shows all node types inline near the cursor/selection.
Expand Down Expand Up @@ -98,7 +99,7 @@ export class InlineNodeTypePicker {
itemEl.addEventListener("mousedown", (e) => {
e.preventDefault();
e.stopPropagation();
void this.selectItem(item);
this.selectItem(item);
});

itemEl.addEventListener("mouseenter", () => {
Expand Down Expand Up @@ -138,14 +139,22 @@ export class InlineNodeTypePicker {
}
}

private async selectItem(item: DiscourseNode) {
private selectItem(item: DiscourseNode) {
this.close();
await createDiscourseNode({
const currentFile =
this.options.plugin.app.workspace.getActiveViewOfType(MarkdownView)
?.file || undefined;
new ModifyNodeModal(this.options.plugin.app, {
nodeTypes: this.options.plugin.settings.nodeTypes,
plugin: this.options.plugin,
nodeType: item,
text: this.options.selectedText,
editor: this.options.editor,
});
initialTitle: this.options.selectedText,
initialNodeType: item,
currentFile,
onSubmit: createModifyNodeModalSubmitHandler(
this.options.plugin,
this.options.editor,
),
}).open();
}

private setupEventHandlers() {
Expand Down Expand Up @@ -173,7 +182,7 @@ export class InlineNodeTypePicker {
e.stopPropagation();
const selectedItem = this.items[this.selectedIndex];
if (selectedItem) {
void this.selectItem(selectedItem);
this.selectItem(selectedItem);
}
} else if (e.key === "Escape") {
e.preventDefault();
Expand Down
Loading