✨ feat(vscode): 代码阅读侧栏拆成多栏:常驻未提交的更改、收藏目录各占一栏
This commit is contained in:
1 parent
45e526afa9
commit
b40ddb5e3a
27 files changed
+2427
-674
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import type { Memento } from 'vscode'
|
||||
import { commands } from 'vscode'
|
||||
|
||||
/** 开关存在 workspaceState 的哪个键、标题栏按哪个上下文键换着显示「隐藏 / 显示测试文件」。 */
|
||||
export interface TestsToggleKeys {
|
||||
state: string
|
||||
context: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 一栏标题栏上「隐藏 / 显示测试文件」的开关:各栏各一个(主栏的审查、「未提交的更改」),按工作区记住;
|
||||
* 上下文键跟着开关走,标题栏按它换着显示两个按钮。
|
||||
*/
|
||||
export class TestsToggle {
|
||||
private value: boolean
|
||||
|
||||
/**
|
||||
* @param state workspaceState
|
||||
* @param keys 开关记在哪、上下文键叫什么
|
||||
* @param changed 开关换了:这一栏按新开关重摆
|
||||
*/
|
||||
constructor(private readonly state: Memento, private readonly keys: TestsToggleKeys, private readonly changed: () => void) {
|
||||
this.value = state.get<boolean>(keys.state) ?? false
|
||||
void commands.executeCommand('setContext', keys.context, this.value)
|
||||
}
|
||||
|
||||
/** 隐藏着测试文件:摆树时把测试文件剔掉 */
|
||||
get hidden(): boolean {
|
||||
return this.value
|
||||
}
|
||||
|
||||
/** 标题栏的「隐藏 / 显示测试文件」:换开关、按工作区记住,这一栏马上按新开关重摆。 */
|
||||
async set(hidden: boolean): Promise<void> {
|
||||
this.value = hidden
|
||||
this.changed()
|
||||
await Promise.all([
|
||||
commands.executeCommand('setContext', this.keys.context, hidden),
|
||||
this.state.update(this.keys.state, hidden || undefined),
|
||||
])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user