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

Method createInlineTask

src/main.ts:1901–1952  ·  view source on GitHub ↗

* Create a new inline task at cursor position * Opens the task creation modal, then inserts a link to the created task * Handles two scenarios: * 1. Cursor on blank line: add new inline task * 2. Cursor anywhere else: start new line then create inline task

(editor: Editor)

Source from the content-addressed store, hash-verified

1899 * 2. Cursor anywhere else: start new line then create inline task
1900 */
1901 async createInlineTask(editor: Editor): Promise<void> {
1902 try {
1903 const cursor = editor.getCursor();
1904 const currentLine = editor.getLine(cursor.line);
1905 const lineContent = currentLine.trim();
1906
1907 // Determine insertion point
1908 let insertionPoint: { line: number; ch: number };
1909
1910 // Scenario 1: Cursor on blank line
1911 if (lineContent === "") {
1912 insertionPoint = { line: cursor.line, ch: cursor.ch };
1913 }
1914 // Scenario 2: Cursor anywhere else - create new line
1915 else {
1916 // Insert a new line and position cursor there
1917 const endOfLine = { line: cursor.line, ch: currentLine.length };
1918 editor.replaceRange("\n", endOfLine);
1919 insertionPoint = { line: cursor.line + 1, ch: 0 };
1920 }
1921
1922 // Store the insertion context for the callback
1923 const insertionContext = {
1924 editor,
1925 insertionPoint,
1926 };
1927
1928 const prePopulatedValues = this.applyParentNoteProjectDefault(
1929 undefined,
1930 "inline-creation"
1931 );
1932
1933 // Open task creation modal with callback to insert link
1934 // Use modal-inline-creation context for inline folder behavior (Issue #1424)
1935 const modal = new TaskCreationModal(this.app, this, {
1936 prePopulatedValues,
1937 onTaskCreated: (task: TaskInfo) => {
1938 this.handleInlineTaskCreated(task, insertionContext);
1939 },
1940 creationContext: "modal-inline-creation",
1941 });
1942
1943 modal.open();
1944 } catch (error) {
1945 tasknotesLogger.error("Error creating inline task:", {
1946 category: "persistence",
1947 operation: "creating-inline-task",
1948 error: error,
1949 });
1950 new Notice("Failed to create inline task");
1951 }
1952 }
1953
1954 /**
1955 * Handle task creation completion - insert link at the determined position

Callers 1

Calls 7

getCursorMethod · 0.80
getLineMethod · 0.80
replaceRangeMethod · 0.80
errorMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected