MCPcopy
hub / github.com/callumalpass/tasknotes / handleInlineTaskCreated

Method handleInlineTaskCreated

src/main.ts:1957–2002  ·  view source on GitHub ↗

* Handle task creation completion - insert link at the determined position

(
		task: TaskInfo,
		context: {
			editor: Editor;
			insertionPoint: { line: number; ch: number };
		}
	)

Source from the content-addressed store, hash-verified

1955 * Handle task creation completion - insert link at the determined position
1956 */
1957 private handleInlineTaskCreated(
1958 task: TaskInfo,
1959 context: {
1960 editor: Editor;
1961 insertionPoint: { line: number; ch: number };
1962 }
1963 ): void {
1964 try {
1965 const { editor, insertionPoint } = context;
1966
1967 // Create link using Obsidian's generateMarkdownLink
1968 const file = this.app.vault.getAbstractFileByPath(task.path);
1969 if (!(file instanceof TFile)) {
1970 new Notice("Failed to create link - file not found");
1971 return;
1972 }
1973
1974 const currentFile = this.app.workspace.getActiveFile();
1975 const sourcePath = currentFile?.path || "";
1976 const properLink = this.app.fileManager.generateMarkdownLink(
1977 file,
1978 sourcePath,
1979 "",
1980 task.title // Use task title as alias
1981 );
1982
1983 // Insert the link at the determined insertion point
1984 editor.replaceRange(properLink, insertionPoint);
1985
1986 // Position cursor at end of inserted link
1987 const newCursor = {
1988 line: insertionPoint.line,
1989 ch: insertionPoint.ch + properLink.length,
1990 };
1991 editor.setCursor(newCursor);
1992
1993 new Notice(`Inline task "${task.title}" created and linked successfully`);
1994 } catch (error) {
1995 tasknotesLogger.error("Error handling inline task creation:", {
1996 category: "persistence",
1997 operation: "handling-inline-task-creation",
1998 error: error,
1999 });
2000 new Notice("Failed to insert task link");
2001 }
2002 }
2003}

Callers 1

createInlineTaskMethod · 0.95

Calls 6

getAbstractFileByPathMethod · 0.80
getActiveFileMethod · 0.80
generateMarkdownLinkMethod · 0.80
replaceRangeMethod · 0.80
setCursorMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected