Skip to content

Commit bb5607f

Browse files
trangdoan982claude
andauthored
ENG-1628: Open ModifyNodeModal with pre-filled text on editor right-click (#990)
* ENG-1628: Open ModifyNodeModal with pre-filled text on editor right-click When a user right-clicks highlighted text and selects a node type from the "Turn into discourse node" submenu, open ModifyNodeModal pre-filled with the selection and pre-selected node type instead of creating the node directly. Also fix cursor placement in content input to land at the end of pre-filled text rather than the beginning. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Pass currentFile to ModifyNodeModal in editor context menu handler Fixes missing relationship dropdown when opening the modal from the right-click menu — without currentFile, availableRelationships returns empty. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f2bf048 commit bb5607f

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

apps/obsidian/src/components/ModifyNodeModal.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,14 @@ export const ModifyNodeForm = ({
177177
}
178178
}, [activeIndex, isOpen]);
179179

180-
// Focus the content input on mount so users can start typing immediately
180+
// Focus the content input on mount so users can start typing immediately,
181+
// with cursor placed at the end of any pre-filled text
181182
useEffect(() => {
182-
titleInputRef.current?.focus();
183+
const el = titleInputRef.current;
184+
if (!el) return;
185+
el.focus();
186+
const len = el.value.length;
187+
el.setSelectionRange(len, len);
183188
}, []);
184189

185190
useEffect(() => {

apps/obsidian/src/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import {
1818
} from "~/utils/editorMenuUtils";
1919
import { createImageEmbedHoverExtension } from "~/utils/imageEmbedHoverIcon";
2020
import { createWikilinkDragExtension } from "~/utils/wikilinkDragHandler";
21-
import { registerCommands } from "~/utils/registerCommands";
21+
import {
22+
registerCommands,
23+
createModifyNodeModalSubmitHandler,
24+
} from "~/utils/registerCommands";
2225
import { DiscourseContextView } from "~/components/DiscourseContextView";
2326
import { VIEW_TYPE_TLDRAW_DG_PREVIEW, FRONTMATTER_KEY } from "~/constants";
24-
import {
25-
convertPageToDiscourseNode,
26-
createDiscourseNode,
27-
} from "~/utils/createNode";
27+
import { convertPageToDiscourseNode } from "~/utils/createNode";
2828
import { DEFAULT_SETTINGS } from "~/constants";
2929
import ModifyNodeModal from "~/components/ModifyNodeModal";
3030
import { TagNodeHandler } from "~/utils/tagNodeHandler";
@@ -222,17 +222,22 @@ export default class DiscourseGraphPlugin extends Plugin {
222222
if (!editor.getSelection()) return;
223223

224224
const selection = editor.getSelection().trim();
225+
const currentFile =
226+
this.app.workspace.getActiveViewOfType(MarkdownView)?.file ||
227+
undefined;
225228
addConvertSubmenu({
226229
menu,
227230
label: "Turn into discourse node",
228231
nodeTypes: this.settings.nodeTypes,
229-
onClick: async (nodeType) => {
230-
await createDiscourseNode({
232+
onClick: (nodeType) => {
233+
new ModifyNodeModal(this.app, {
234+
nodeTypes: this.settings.nodeTypes,
231235
plugin: this,
232-
editor,
233-
nodeType,
234-
text: selection,
235-
});
236+
initialTitle: selection,
237+
initialNodeType: nodeType,
238+
currentFile,
239+
onSubmit: createModifyNodeModalSubmitHandler(this, editor),
240+
}).open();
236241
},
237242
});
238243
}),

apps/obsidian/src/utils/registerCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ModifyNodeSubmitParams = {
2424
relationshipTargetFile?: TFile;
2525
};
2626

27-
const createModifyNodeModalSubmitHandler = (
27+
export const createModifyNodeModalSubmitHandler = (
2828
plugin: DiscourseGraphPlugin,
2929
editor?: Editor,
3030
): ((params: ModifyNodeSubmitParams) => Promise<void>) => {

0 commit comments

Comments
 (0)