web: abbreviate the home directory in chat group labels

Use ~ for the server home prefix in directory bands and row meta, with the
full path still in the band's tooltip. Keeps long repository paths readable
inside the centred collapsible header.
This commit is contained in:
2026-10-20 14:39:15 +01:00
parent 3799d37d7c
commit f982c0b712
5 changed files with 65 additions and 10 deletions
+24 -8
View File
@@ -77,6 +77,7 @@ import {
applyChatEvent,
applyChatOverrides,
applyChatPermission,
abbreviateHome,
appendChatNotice,
approvalCard,
attachmentDisplayName,
@@ -114,6 +115,7 @@ import {
groupSessionsByDirectory,
hideChatOverride,
historyResync,
homeDirectoryFor,
isChatSessionUnseen,
makeChatNotice,
markChatUnseen,
@@ -1852,6 +1854,16 @@ function renderChatList() {
return list;
}
/** The home prefix used to shorten directory labels to `~`, when knowable. */
function chatHomePrefix() {
const reported = String(state.chatDirectories?.[0] ?? "").trim();
if (reported !== "") return reported;
return homeDirectoryFor([
...(state.chatDirectories ?? []),
...(state.chatSessions ?? []).map((session) => session?.directory),
]);
}
/** The list body: the loading/error/empty states or the grouped session rows. */
function fillChatRows(rows) {
rows.replaceChildren();
@@ -1892,6 +1904,7 @@ function fillChatRows(rows) {
return;
}
const home = chatHomePrefix();
const starred = filtered.filter(
(session) => !session.closed && state.chatStars?.has?.(session.id) === true,
);
@@ -1910,18 +1923,19 @@ function fillChatRows(rows) {
h("span", { class: "chat-group-title", text: "Starred" }),
),
);
for (const session of starred) rows.append(renderChatRow(session, duplicateTitles));
for (const session of starred) rows.append(renderChatRow(session, duplicateTitles, home));
}
const groups = groupSessionsByDirectory(active);
if (groups.length > 1) {
for (const group of groups) {
const label = directoryLabel(group.directory);
const fullLabel = directoryLabel(group.directory);
const label = abbreviateHome(fullLabel, home);
const key = String(group.directory ?? "");
const collapsed = state.chatCollapsedDirs?.has?.(key) === true;
const toggle = h("button", {
class: "chat-group-header chat-group-toggle chat-group-directory",
type: "button",
title: label,
title: fullLabel,
"aria-expanded": collapsed ? "false" : "true",
"aria-label": `${collapsed ? "Expand" : "Collapse"} ${label}`,
onclick: () => {
@@ -1935,11 +1949,11 @@ function fillChatRows(rows) {
toggle.append(h("span", { class: "chevron", text: collapsed ? "\u25b8" : "\u25be" }));
rows.append(toggle);
if (!collapsed) {
for (const session of group.sessions) rows.append(renderChatRow(session, duplicateTitles));
for (const session of group.sessions) rows.append(renderChatRow(session, duplicateTitles, home));
}
}
} else {
for (const session of active) rows.append(renderChatRow(session, duplicateTitles));
for (const session of active) rows.append(renderChatRow(session, duplicateTitles, home));
}
if (closed.length > 0) {
const open = state.chatClosedOpen === true;
@@ -1959,7 +1973,7 @@ function fillChatRows(rows) {
});
rows.append(toggle);
if (open) {
for (const session of closed) rows.append(renderChatRow(session, duplicateTitles));
for (const session of closed) rows.append(renderChatRow(session, duplicateTitles, home));
}
}
if (state.chatError) {
@@ -2009,7 +2023,7 @@ async function toggleChatStar(id) {
* activity badge word, the work-label meta line and the close/reopen action.
* Every server string is set with textContent.
*/
function renderChatRow(session, duplicateTitles = new Set()) {
function renderChatRow(session, duplicateTitles = new Set(), home = "") {
const open = state.chatActiveId === session.id;
const thread = state.chatThreads.get(session.id) ?? null;
const unseen =
@@ -2060,7 +2074,9 @@ function renderChatRow(session, duplicateTitles = new Set()) {
head.append(h("span", { class: `chat-activity ${statusClass}`, text: statusWord }));
}
sessionButton.append(head);
const meta = [updated, String(session.directory ?? "").trim()].filter(Boolean).join(" \u00b7 ");
const meta = [updated, abbreviateHome(String(session.directory ?? "").trim(), home)]
.filter(Boolean)
.join(" \u00b7 ");
if (meta !== "") {
sessionButton.append(h("span", { class: "row-meta chat-row-meta", text: meta }));
}