feat: 完善文档集管理功能

- 新增文档集保存功能,支持命名和时间戳
   - 实现文档集删除功能
   - 添加文档集列表展示界面
   - 优化文档集 UI 样式和交互
This commit is contained in:
Roe-xin
2026-03-17 16:44:39 +08:00
parent 64cce80a70
commit ada3a3bffd
4 changed files with 112 additions and 3 deletions

View File

@ -142,6 +142,39 @@ export function addToDocumentSet(docs: Array<{ path: string; relativePath: strin
documentSet = [...documentSet, ...docs];
}
export function saveDocumentSet(docs: Array<{ path: string; relativePath: string }>) {
documentSet = docs;
export function saveDocumentSet(
docs: Array<{ path: string; relativePath: string }>,
name: string,
panel: vscode.WebviewPanel
) {
const newDocSet = {
id: Date.now().toString(),
name,
documents: docs,
updatedAt: new Date().toISOString(),
};
documentSets.push(newDocSet);
panel.webview.postMessage({
command: "documentSetSaved",
documentSets: documentSets,
});
}
let documentSets: Array<{
id: string;
name: string;
documents: Array<{ path: string; relativePath: string }>;
updatedAt: string;
}> = [];
export function getDocumentSets() {
return documentSets;
}
export function deleteDocumentSet(id: string, panel: vscode.WebviewPanel) {
documentSets = documentSets.filter(ds => ds.id !== id);
panel.webview.postMessage({
command: "documentSetSaved",
documentSets: documentSets,
});
}

View File

@ -368,7 +368,12 @@ export async function handleWebviewMessage(
case "saveDocumentSet":
const { saveDocumentSet } = await import("./contextHelper");
saveDocumentSet(message.documents || []);
saveDocumentSet(message.documents || [], message.name || "", panel);
break;
case "deleteDocumentSet":
const { deleteDocumentSet } = await import("./contextHelper");
deleteDocumentSet(message.id, panel);
break;
case "openContextSettings":

View File

@ -110,6 +110,47 @@ export function getContextSettingsComponentStyles(): string {
font-size: 13px;
}
.docset-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px;
border: 1px solid var(--vscode-panel-border);
border-radius: 6px;
margin-bottom: 8px;
background: var(--vscode-editor-background);
}
.docset-item:hover {
background: var(--vscode-list-hoverBackground);
}
.docset-name {
font-size: 13px;
font-weight: 500;
}
.docset-meta {
font-size: 11px;
color: var(--vscode-descriptionForeground);
flex: 1;
}
.docset-delete-btn {
background: transparent;
border: none;
color: var(--vscode-foreground);
cursor: pointer;
padding: 4px;
opacity: 0.6;
border-radius: 4px;
}
.docset-delete-btn:hover {
opacity: 1;
background: var(--vscode-toolbar-hoverBackground);
}
${getDocsetDialogStyles()}
`;
}

View File

@ -286,6 +286,34 @@ export function getDocsetDialogScript(): string {
closeDocsetDialog();
}
function renderDocumentSets(documentSets) {
const listEl = document.getElementById('contextDocsList');
if (!listEl) return;
if (!documentSets || documentSets.length === 0) {
listEl.innerHTML = '<div class="context-empty"><p>暂无文档集</p></div>';
return;
}
listEl.innerHTML = documentSets.map(ds => \`
<div class="docset-item">
<div class="docset-name">\${ds.name}</div>
<div class="docset-meta">更新于 \${new Date(ds.updatedAt).toLocaleString('zh-CN')}</div>
<button class="docset-delete-btn" onclick="deleteDocumentSet('\${ds.id}')">
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">
<path d="M10 3h3v1h-1v9l-1 1H4l-1-1V4H2V3h3V2a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v1zM9 2H6v1h3V2zM4 13h7V4H4v9zm2-8H5v7h1V5zm1 0h1v7H7V5zm2 0h1v7H9V5z"/>
</svg>
</button>
</div>
\`).join('');
}
function deleteDocumentSet(id) {
if (confirm('确定删除此文档集?')) {
vscode.postMessage({ command: 'deleteDocumentSet', id });
}
}
window.addEventListener('message', event => {
const message = event.data;
if (message.command === 'filesSelectedForDocset') {
@ -294,6 +322,8 @@ export function getDocsetDialogScript(): string {
}
docsetFiles = [...docsetFiles, ...message.files];
updateDocsetDisplay();
} else if (message.command === 'documentSetSaved') {
renderDocumentSets(message.documentSets);
}
});
`;