fix(web): keep chat row actions visible in reserved columns
This commit is contained in:
+15
-19
@@ -1187,31 +1187,16 @@ function effectiveChatSession(session) {
|
||||
|
||||
|
||||
function openChatMenu(sessionId) {
|
||||
const scrollTop = document.getElementById("chatRows")?.scrollTop ?? 0;
|
||||
state.chatMenu = state.chatMenu === sessionId ? null : sessionId;
|
||||
renderContent();
|
||||
const rows = document.getElementById("chatRows");
|
||||
if (rows) rows.scrollTop = scrollTop;
|
||||
if (state.chatMenu) {
|
||||
// The panel hangs below its button. Near the bottom of the window that would
|
||||
// put the items off-screen (a real hit-test failure, not just clipping), so
|
||||
// flip the panel above the row when it does not fit below.
|
||||
const row = document.querySelector(`#chatRows .chat-row[data-session="${CSS.escape(sessionId)}"]`);
|
||||
const panel = row?.querySelector(".chat-menu-panel");
|
||||
if (panel && panel.getBoundingClientRect().bottom > window.innerHeight - 8) {
|
||||
panel.style.top = "auto";
|
||||
panel.style.bottom = "calc(100% + 4px)";
|
||||
}
|
||||
// Flipping is not always enough: a row at the very bottom edge can leave the
|
||||
// panel (and its items) below the viewport even when it opens upwards. Bring
|
||||
// the row into view so the menu is actually reachable.
|
||||
if (panel && row) {
|
||||
const rect = panel.getBoundingClientRect();
|
||||
if (rect.top < 8 || rect.bottom > window.innerHeight - 8) {
|
||||
row.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
}
|
||||
// The re-render replaced the focused button; move focus into the panel so a
|
||||
// keyboard operator can walk the items without hunting for the next Tab stop.
|
||||
const first = document.querySelector(`#chatRows .chat-row[data-session="${CSS.escape(sessionId)}"] .chat-menu-item`);
|
||||
first?.focus();
|
||||
first?.focus({ preventScroll: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2466,6 +2451,17 @@ function renderChatActionsMenu(session, duplicateTitles = new Set()) {
|
||||
}),
|
||||
);
|
||||
wrap.append(menu);
|
||||
// Measure after mounting (and after openChatMenu restores list scroll), but
|
||||
// before painting. Re-anchor on every render, not only the initial click.
|
||||
queueMicrotask(() => {
|
||||
if (!menu.isConnected) return;
|
||||
const anchor = wrap.querySelector(".chat-menu-button").getBoundingClientRect();
|
||||
const rect = menu.getBoundingClientRect();
|
||||
const below = anchor.bottom + 4;
|
||||
const top = below + rect.height <= window.innerHeight - 8 ? below : anchor.top - rect.height - 4;
|
||||
menu.style.left = `${Math.max(8, Math.min(anchor.right - rect.width, window.innerWidth - rect.width - 8))}px`;
|
||||
menu.style.top = `${Math.max(8, Math.min(top, window.innerHeight - rect.height - 8))}px`;
|
||||
});
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user