MCPcopy Create free account
hub / github.com/chhoumann/quickadd / openExistingFileTab

Function openExistingFileTab

src/utils/fileOpening.ts:258–286  ·  view source on GitHub ↗
(
	app: App,
	file: TFile,
	focus = true,
)

Source from the content-addressed store, hash-verified

256 * Returns the leaf if found, otherwise `null`.
257 */
258export function openExistingFileTab(
259 app: App,
260 file: TFile,
261 focus = true,
262): WorkspaceLeaf | null {
263 let leaf: WorkspaceLeaf | undefined = undefined;
264
265 app.workspace.iterateRootLeaves((m_leaf: WorkspaceLeaf) => {
266 const view = m_leaf.view;
267 if (view instanceof FileView) {
268 if (view.file) {
269 if (
270 view.file === file ||
271 areSameVaultFilePath(file.path, view.file.path)
272 ) {
273 leaf = m_leaf;
274 return;
275 }
276 }
277 }
278 });
279 if (leaf !== undefined) {
280 if (focus) {
281 app.workspace.setActiveLeaf(leaf, { focus: true });
282 }
283 return leaf;
284 }
285 return null;
286}

Callers 4

runMethod · 0.85
runMethod · 0.85

Calls 1

areSameVaultFilePathFunction · 0.85

Tested by

no test coverage detected