* 在主窗口打开评论面板 * 如果面板已在侧边栏打开,则移动到主窗口
()
| 70 | * 如果面板已在侧边栏打开,则移动到主窗口 |
| 71 | */ |
| 72 | async openCommentPanelInMainWindow(): Promise<void> { |
| 73 | const { workspace } = this.app; |
| 74 | |
| 75 | // 检查评论面板是否已经打开 |
| 76 | const existing = workspace.getLeavesOfType(VIEW_TYPE_HINOTE); |
| 77 | if (existing.length) { |
| 78 | // 如果已经打开,尝试将其移动到主视图区域 |
| 79 | const existingLeaf = existing[0]; |
| 80 | |
| 81 | // 先激活现有视图 |
| 82 | workspace.setActiveLeaf(existingLeaf, { focus: true }); |
| 83 | |
| 84 | // 使用另一种方式将视图移动到主视图区域 |
| 85 | // 先分离当前叶子 |
| 86 | workspace.detachLeavesOfType(VIEW_TYPE_HINOTE); |
| 87 | |
| 88 | // 然后在主视图区域创建新的叶子(使用tab而不是split避免分屏) |
| 89 | const newLeaf = workspace.getLeaf('tab'); |
| 90 | await newLeaf.setViewState({ |
| 91 | type: VIEW_TYPE_HINOTE, |
| 92 | active: true, |
| 93 | }); |
| 94 | |
| 95 | // 将视图标记为主窗口模式 |
| 96 | const view = newLeaf.view; |
| 97 | if (view && view instanceof HiNoteView) { |
| 98 | await this.updateViewToMainMode(view); |
| 99 | } |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | // 如果评论面板未打开,在主视图区域创建新标签页 |
| 104 | const leaf = workspace.getLeaf('tab'); |
| 105 | if (leaf) { |
| 106 | await leaf.setViewState({ |
| 107 | type: VIEW_TYPE_HINOTE, |
| 108 | active: true, |
| 109 | }); |
| 110 | |
| 111 | // 将新创建的视图标记为主窗口模式 |
| 112 | window.setTimeout(() => { |
| 113 | const view = leaf.view; |
| 114 | if (view && view instanceof HiNoteView) { |
| 115 | void this.updateViewToMainMode(view); |
| 116 | } |
| 117 | }, 100); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * 更新视图为主窗口模式 |
no test coverage detected