✨ feat(vscode): 代码阅读侧栏行加复制菜单,块按钮只留图标,筛选菜单加全选 / 取消全选

This commit is contained in:
cruldra committed 2026-09-26 20:39:21 +08:00
1 parent 631699a570
commit c84e21ff57
16 files changed
+555 -119

No files matched your search

@@ -1,7 +1,4 @@
import { readFileSync } from 'node:fs'
import * as path from 'node:path'
import { describe, expect, it } from 'vitest'
import { entryContext } from '../explorer/fileEntries'
import { escapeMarkdown, noteDecoration } from './noteItem'
describe('树上的一行', () => {
@@ -23,31 +20,3 @@ describe('树上的一行', () => {
.toBe('\\*\\*别加粗\\*\\* \\<b\\>x\\<\\/b\\> \\[链接\\]\\(command\\:x\\) \\`代码\\` \\# 标题 \\$\\(icon\\)')
})
})
describe('菜单按 contextValue 挂按钮', () => {
interface MenuItem { command: string, when: string, group: string }
const menus = (JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), 'utf8')) as {
contributes: { menus: Record<string, MenuItem[]> }
}).contributes.menus['view/item/context']
/** 这一行在某个组(行尾按钮 inline / 右键菜单)里有哪些注释命令 */
function commandsFor(contextValue: string, group: string): string[] {
return menus
.filter(item => item.group === group && item.when.includes('view == superpowers.codeReader.files'))
.filter((item) => {
const pattern = /viewItem =~ \/(.+)\/$/.exec(item.when)?.[1]
return pattern !== undefined && new RegExp(pattern).test(contextValue)
})
.map(item => item.command)
}
const noted = (context: string): string => noteDecoration(context, 'x', '注释')!.contextValue
it.each(['inline', 'notes'])('%s:没注释的目录 / 文件只有「添加注释」,有注释的只有「编辑注释」,工作区根都没有', (group) => {
for (const context of [entryContext({ isDirectory: false, isRoot: false }), entryContext({ isDirectory: true, isRoot: false })]) {
expect(commandsFor(context, group)).toEqual(['superpowers.codeReader.addNote'])
expect(commandsFor(noted(context), group)).toEqual(['superpowers.codeReader.editNote'])
}
expect(commandsFor(entryContext({ isDirectory: true, isRoot: true }), group)).toEqual([])
})
})