优化目录候选文件名显示并重新打包

This commit is contained in:
shiyue
2026-09-11 13:56:43 +08:00
parent b8fcc12229
commit 965aefe9a4
6 changed files with 371 additions and 14 deletions

View File

@@ -11556,6 +11556,30 @@
};
}
function getComposerFileSuggestionDisplay(item) {
const rawName = String(item?.name || item?.label || item?.insertion || '').trim();
const normalizedName = rawName
.replace(/^@/, '')
.replace(/\\/g, '/')
.replace(/\/+$/, '');
const segments = normalizedName.split('/').filter(Boolean);
const basename = segments.pop() || normalizedName || rawName;
const parentPath = segments.join('/');
const isDirectory = item?.itemType === 'directory';
const primaryText = `${basename}${isDirectory ? '/' : ''}`;
const parentLabel = parentPath ? `@${parentPath}/` : '';
const fallbackDescription = String(item?.description || '').trim();
const secondaryText = [parentLabel, parentLabel ? '' : fallbackDescription]
.filter(Boolean)
.join(' · ')
|| fallbackDescription;
return {
primaryText,
secondaryText,
fullPath: String(item?.label || item?.insertion || rawName).trim(),
};
}
function showCmdMenu(token, items) {
const safeItems = Array.isArray(items) ? items : [];
if (!token || safeItems.length === 0) {
@@ -11565,6 +11589,8 @@
activeComposerToken = token;
cmdMenuIndex = 0;
cmdMenu.innerHTML = safeItems.map((item, i) => {
const isFileSuggestion = item.kind === 'file';
const fileDisplay = isFileSuggestion ? getComposerFileSuggestionDisplay(item) : null;
const kindLabel = item.kind === 'skill'
? 'Skill'
: item.kind === 'prompt'
@@ -11574,11 +11600,14 @@
: item.kind === 'mcp'
? 'MCP'
: 'Cmd';
return `<div class="cmd-item${i === 0 ? ' active' : ''}" data-index="${i}">
const primaryText = fileDisplay?.primaryText || item.label || item.name || item.insertion || '';
const secondaryText = fileDisplay?.secondaryText || item.description || item.title || '';
const fullPathTitle = fileDisplay?.fullPath ? ` title="${escapeHtmlAttr(fileDisplay.fullPath)}"` : '';
return `<div class="cmd-item${i === 0 ? ' active' : ''}${isFileSuggestion ? ' file-suggestion' : ''}" data-index="${i}"${fullPathTitle}>
<span class="cmd-item-kind">${kindLabel}</span>
<span class="cmd-item-main">
<span class="cmd-item-cmd">${escapeHtml(item.label || item.name || item.insertion || '')}</span>
<span class="cmd-item-desc">${escapeHtml(item.description || item.title || '')}</span>
<span class="cmd-item-cmd">${escapeHtml(primaryText)}</span>
<span class="cmd-item-desc">${escapeHtml(secondaryText)}</span>
</span>
</div>`;
}).join('');