✨ feat(vscode): 代码阅读侧栏右键菜单加「在 Finder 中显示」,按系统换成文件资源管理器 / 打开所在的文件夹

This commit is contained in:
cruldra committed 2026-10-08 07:17:26 +08:00
1 parent 430f98ade4
commit 5ce2e904f4
5 files changed
+121 -3

No files matched your search

@@ -73,7 +73,7 @@ describe('侧栏行尾按钮', () => {
})
it('分组行(「暂存的更改」「更改」)什么按钮、菜单都没有', () => {
for (const group of ['inline', 'copy', 'notes'])
for (const group of ['inline', 'copy', 'fileManager', 'notes'])
expect(itemsFor('view/item/context', group, GROUP_CONTEXT)).toEqual([])
expect(itemsFor(COPY_MENU, 'copy', GROUP_CONTEXT)).toEqual([])
})
@@ -136,6 +136,48 @@ describe('右键菜单的注释', () => {
})
})
describe('右键菜单的「在系统文件管理器中显示」', () => {
/** 菜单上的字跟着系统走,和 VS Code 自带资源管理器一样 */
const REVEALS = [
{ platform: 'isMac', command: 'superpowers.codeReader.revealInFinder', title: '在 Finder 中显示' },
{ platform: 'isWindows', command: 'superpowers.codeReader.revealInFileExplorer', title: '在文件资源管理器中显示' },
{ platform: 'isLinux', command: 'superpowers.codeReader.openContainingFolder', title: '打开所在的文件夹' },
]
const REVEAL_IDS = REVEALS.map(item => item.command)
const whenOf = (command: string): string | undefined => menus['view/item/context'].find(item => item.command === command)?.when
it('文件、文件夹(含未提交、有注释)都有,工作区根没有;审查时也不藏', () => {
for (const context of [file, folder, unstaged, noted(file), noted(folder), noted(unstaged)])
expect(itemsFor('view/item/context', 'fileManager', context)).toEqual(REVEAL_IDS)
expect(itemsFor('view/item/context', 'fileManager', root)).toEqual([])
expect(REVEAL_IDS.some(id => whenOf(id)?.includes('filter'))).toBe(false)
})
it('每个系统只出自己那一项,字和 VS Code 自带的一样', () => {
for (const { platform, command, title } of REVEALS) {
const when = whenOf(command)
expect(when).toContain(`&& ${platform} &&`)
for (const other of REVEALS.filter(item => item.platform !== platform))
expect(when).not.toContain(other.platform)
expect(commands.find(item => item.command === command)?.title).toBe(title)
}
})
it('自成一组,排在复制后面、注释前面(VS Code 按组名的字母序排组,组和组之间画分隔线)', () => {
const groups = menus['view/item/context']
.filter(item => item.when.includes('view == superpowers.codeReader.files') && item.group !== undefined && !item.group.startsWith('inline'))
.map(item => item.group!.split('@')[0])
expect([...new Set(groups)].sort((a, b) => a.localeCompare(b))).toEqual(['copy', 'fileManager', 'notes'])
})
it('只在右键菜单里,不挂行尾按钮,命令面板里藏起来', () => {
for (const id of REVEAL_IDS) {
expect(menus['view/item/context'].filter(item => item.command === id)).toHaveLength(1)
expect(menus.commandPalette.find(item => item.command === id)?.when).toBe('false')
}
})
})
describe('筛选(审查工单、未提交的更改)', () => {
const FILTER = 'superpowers.codeReader.filter'
const PICK = 'superpowers.codeReader.pickReviewIssue'