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

Function openFileByPath

e2e/release-gifs.spec.ts:164–185  ·  view source on GitHub ↗
(page: Page, relativePath: string)

Source from the content-addressed store, hash-verified

162}
163
164async function openFileByPath(page: Page, relativePath: string): Promise<void> {
165 const opened = await page.evaluate(async (targetPath) => {
166 const obsidianApp = (window as any).app;
167 const file = obsidianApp?.vault?.getAbstractFileByPath?.(targetPath);
168 if (!file) return false;
169 await obsidianApp.workspace.getLeaf(true).openFile(file);
170 return true;
171 }, relativePath);
172
173 if (!opened) {
174 throw new Error(`Could not open ${relativePath}`);
175 }
176
177 const fileLabel = path.basename(relativePath, path.extname(relativePath));
178 const tabHeader = page.locator(`.workspace-tab-header:has-text("${fileLabel}")`).last();
179 if (await tabHeader.isVisible({ timeout: 5000 }).catch(() => false)) {
180 await tabHeader.click();
181 await page.waitForTimeout(400);
182 }
183
184 await page.waitForTimeout(1400);
185}
186
187async function reloadWithoutSaving(page: Page): Promise<void> {
188 await runCommand(page, "Reload app without saving");

Callers 3

openTaskListByPathFunction · 0.85
openCalendarByPathFunction · 0.85
openTaskNoteFunction · 0.85

Calls 3

getAbstractFileByPathMethod · 0.80
getLeafMethod · 0.80
basenameMethod · 0.80

Tested by

no test coverage detected