| 449 | } |
| 450 | |
| 451 | async function reuseOrCreateEditor(targetDocument: TextDocument) { |
| 452 | // if there's a known text editor for a Uri, use it. if not, open a new one |
| 453 | // 'beside' the current one. We know about the last active, and all visible. |
| 454 | // Sometimes the last active is not visible in the case it was overtaken by a |
| 455 | // WebViewPanel. |
| 456 | |
| 457 | const KnownEditors: TextEditor[] = []; |
| 458 | |
| 459 | KnownEditors.push(lastActiveTextEditor); |
| 460 | KnownEditors.push(...window.visibleTextEditors); |
| 461 | |
| 462 | |
| 463 | const matchingTextEditors = KnownEditors.filter((editor) => |
| 464 | editor.document.uri.toString() === targetDocument.uri.toString()); |
| 465 | |
| 466 | if (matchingTextEditors.length === 0) { |
| 467 | const newEditor = await window.showTextDocument( |
| 468 | targetDocument, |
| 469 | ViewColumn.Beside |
| 470 | ); |
| 471 | return (newEditor); |
| 472 | } |
| 473 | else { |
| 474 | return (matchingTextEditors[0]); |
| 475 | } |
| 476 | } |