( app: App, file: TFile, focus = true, )
| 256 | * Returns the leaf if found, otherwise `null`. |
| 257 | */ |
| 258 | export 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 | } |
no test coverage detected