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

Method insertTaskNoteLink

src/main.ts:1466–1510  ·  view source on GitHub ↗

* Insert a wikilink to a selected tasknote at the current cursor position

(editor: Editor)

Source from the content-addressed store, hash-verified

1464 * Insert a wikilink to a selected tasknote at the current cursor position
1465 */
1466 async insertTaskNoteLink(editor: Editor): Promise<void> {
1467 try {
1468 // Get all tasks
1469 const allTasks = await this.cacheManager.getAllTasks();
1470 const unarchivedTasks = allTasks.filter((task) => !task.archived);
1471
1472 // Open task selector modal
1473 openTaskSelector(this, unarchivedTasks, (selectedTask) => {
1474 if (selectedTask) {
1475 // Create link using Obsidian's generateMarkdownLink (respects user's link format settings)
1476 const file = this.app.vault.getAbstractFileByPath(selectedTask.path);
1477 if (file instanceof TFile) {
1478 const currentFile = this.app.workspace.getActiveFile();
1479 const sourcePath = currentFile?.path || "";
1480 const properLink = this.app.fileManager.generateMarkdownLink(
1481 file,
1482 sourcePath,
1483 "",
1484 selectedTask.title // Use task title as alias
1485 );
1486
1487 // Insert at cursor position
1488 const cursor = editor.getCursor();
1489 editor.replaceRange(properLink, cursor);
1490
1491 // Move cursor to end of inserted text
1492 const newCursor = {
1493 line: cursor.line,
1494 ch: cursor.ch + properLink.length,
1495 };
1496 editor.setCursor(newCursor);
1497 } else {
1498 new Notice("Failed to create link - file not found");
1499 }
1500 }
1501 });
1502 } catch (error) {
1503 tasknotesLogger.error("Error inserting tasknote link:", {
1504 category: "persistence",
1505 operation: "inserting-tasknote-link",
1506 error: error,
1507 });
1508 new Notice("Failed to insert tasknote link");
1509 }
1510 }
1511
1512 /**
1513 * Open task selector to start time tracking for a task

Callers 1

Calls 9

openTaskSelectorFunction · 0.90
getAbstractFileByPathMethod · 0.80
getActiveFileMethod · 0.80
generateMarkdownLinkMethod · 0.80
getCursorMethod · 0.80
replaceRangeMethod · 0.80
setCursorMethod · 0.80
errorMethod · 0.80
getAllTasksMethod · 0.45

Tested by

no test coverage detected