feat(ui): 文件树行内 @ 引用,相对路径插入输入框光标处
This commit is contained in:
@@ -1172,6 +1172,7 @@ body.voice-active .scroll-bottom-btn { display: none; }
|
||||
.tree-act:hover { background: var(--border); color: var(--active); }
|
||||
.tree-act.danger:hover { background: var(--bg-fdf3f2); color: var(--fg-c0392b); }
|
||||
.tree-act svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.tree-act .at-glyph { font-size: 13px; font-weight: 700; line-height: 1; }
|
||||
.tree-empty, .tree-loading, .tree-more { padding: 10px 12px; font-size: 12px; color: var(--gray); }
|
||||
|
||||
/* 行内勾选框:hover 或已选中才淡入;但占位始终在,hover 时文件名不会左右跳。
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
const SVG_DL = '<svg viewBox="0 0 24 24"><use href="#i-download"/></svg>';
|
||||
const SVG_DEL = '<svg viewBox="0 0 24 24"><use href="#i-trash"/></svg>';
|
||||
const SVG_REVEAL_SM = '<svg viewBox="0 0 24 24"><use href="#i-external-b"/></svg>';
|
||||
const SVG_AT = '<span class="at-glyph">@</span>';
|
||||
|
||||
let localCapable = false; // local 启动器:才显示「在 Finder/终端中打开」
|
||||
let showHidden = false;
|
||||
@@ -131,6 +132,8 @@
|
||||
// 行内动作:服务器形态给「下载 / 删除」;local 本就跑在同一台机器上,
|
||||
// 「下载」到本地是多余的(用 Finder 直接看原文件更顺),所以换成「在 Finder 中显示」。
|
||||
if (ent.type === 'file' && !localCapable) row.appendChild(actBtn('download', '下载', SVG_DL, false));
|
||||
// @ 引用:把相对路径插到输入框光标处(目录带尾斜杠,AI 一眼看出该列目录)
|
||||
row.appendChild(actBtn('at', ent.type === 'dir' ? '引用此目录' : '引用到输入框', SVG_AT, false));
|
||||
if (localCapable) row.appendChild(actBtn('reveal', '在 Finder 中显示', SVG_REVEAL_SM, false));
|
||||
row.appendChild(actBtn('delete', '删除', SVG_DEL, true));
|
||||
return row;
|
||||
@@ -380,6 +383,7 @@
|
||||
if (a === 'download') { if (typeof downloadFile === 'function') downloadFile(rel); }
|
||||
else if (a === 'delete') deleteNode(rel, isDir);
|
||||
else if (a === 'reveal') localAction('reveal', rel);
|
||||
else if (a === 'at') insertPathRef(rel, isDir);
|
||||
return;
|
||||
}
|
||||
if (row.classList.contains('is-ignored') || row.dataset.type === 'link') return;
|
||||
@@ -393,6 +397,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
// @ 引用:把相对路径插到对话框光标处。插的是纯相对路径,不带 @ 前缀——
|
||||
// @<会话id>/<rel> 是跨会话只读路径的语法(resolvePastPath),带上会被当成会话 id 而报错。
|
||||
// 相对路径正是 read_file / list_directory 直接认的形态。
|
||||
function insertPathRef(rel, isDir) {
|
||||
const ta = $('msg-input');
|
||||
if (!ta || !rel) return;
|
||||
const txt = isDir ? rel + '/' : rel;
|
||||
const s = ta.selectionStart == null ? ta.value.length : ta.selectionStart;
|
||||
const e = ta.selectionEnd == null ? s : ta.selectionEnd;
|
||||
const before = ta.value.slice(0, s);
|
||||
const after = ta.value.slice(e);
|
||||
// 前后补空格:粘在已有文字上会让路径和句子糊成一串,AI 切不开
|
||||
const lead = before && !/\s$/.test(before) ? ' ' : '';
|
||||
const tail = after && !/^\s/.test(after) ? ' ' : '';
|
||||
ta.value = before + lead + txt + tail + after;
|
||||
const pos = (before + lead + txt).length;
|
||||
ta.focus();
|
||||
try { ta.setSelectionRange(pos, pos); } catch (_) { /* 部分环境不支持,光标位置不强求 */ }
|
||||
ta.dispatchEvent(new Event('input', { bubbles: true })); // 发送按钮状态 / 自动高度靠它跟上
|
||||
}
|
||||
|
||||
// local 能力探测结果回来后才把「在 Finder/终端中打开」露出来(服务器形态永远隐藏)
|
||||
|
||||
function syncLocalButtons() {
|
||||
|
||||
Reference in New Issue
Block a user