| 567 | } |
| 568 | |
| 569 | async activateOutlineInSidebar() { |
| 570 | const { workspace } = this.app; |
| 571 | |
| 572 | let leaf = workspace.getLeavesOfType(VIEW_TYPE_CODE_OUTLINE)[0]; |
| 573 | |
| 574 | // 1. 确保视图存在 |
| 575 | if (!leaf) { |
| 576 | const rightLeaf = workspace.getRightLeaf(false); |
| 577 | if (rightLeaf) { |
| 578 | await rightLeaf.setViewState({ |
| 579 | type: VIEW_TYPE_CODE_OUTLINE, |
| 580 | active: true |
| 581 | }); |
| 582 | leaf = workspace.getLeavesOfType(VIEW_TYPE_CODE_OUTLINE)[0]; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | if (!leaf) return; |
| 587 | |
| 588 | // 2. 实现 Toggle 逻辑 |
| 589 | const rightSplit = workspace.rightSplit; |
| 590 | |
| 591 | if (rightSplit.collapsed) { |
| 592 | // 如果侧边栏折叠,展开并显示 |
| 593 | void rightSplit.expand(); |
| 594 | void workspace.revealLeaf(leaf); |
| 595 | } else { |
| 596 | // 如果侧边栏展开 |
| 597 | // 检查当前 Leaf 是否可见(即是否是当前选中的 Tab) |
| 598 | // 使用 offsetParent 判断元素是否显示 |
| 599 | const isVisible = leaf.view.containerEl.offsetParent !== null; |
| 600 | |
| 601 | if (isVisible) { |
| 602 | // 如果当前可见,则折叠侧边栏 |
| 603 | void rightSplit.collapse(); |
| 604 | } else { |
| 605 | // 如果当前被遮挡(其他 Tab 激活),则显示它 |
| 606 | void workspace.revealLeaf(leaf); |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | async updateOutline(file: import("obsidian").TFile, content?: string) { |
| 612 | const outlineLeaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_CODE_OUTLINE); |