mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 11:28:46 +08:00
fix(desktop): cap outline rail at nearby entries and drop overflow indicators
This commit is contained in:
1 parent
66c60f6852
commit
7e86e9e9ad
5 files changed
+63
-19
No files matched your search
@@ -445,7 +445,7 @@ describe("聊天视图", () => {
|
||||
render(<ChatView meta={META} />);
|
||||
await waitFor(() => expect(screen.getByText("帮我修 bug")).toBeTruthy());
|
||||
const nav = await screen.findByRole("navigation", { name: "提问大纲" });
|
||||
fireEvent.mouseEnter(nav.firstElementChild!);
|
||||
fireEvent.mouseEnter(nav.querySelector("[data-outline-dot]")!);
|
||||
// 目录条目在,正文里还没有(在更早的历史页里)
|
||||
expect(screen.getByText("最早的问题")).toBeTruthy();
|
||||
expect(ops.some((o) => o.cmd === "session_history")).toBe(false);
|
||||
@@ -488,9 +488,9 @@ describe("聊天视图", () => {
|
||||
vi.spyOn(first, "getBoundingClientRect").mockReturnValue({ top: 180 } as DOMRect);
|
||||
vi.spyOn(second, "getBoundingClientRect").mockReturnValue({ top: 360 } as DOMRect);
|
||||
const nav = await screen.findByRole("navigation", { name: "提问大纲" });
|
||||
fireEvent.mouseEnter(nav.firstElementChild!);
|
||||
fireEvent.mouseEnter(nav.querySelector("[data-outline-dot]")!);
|
||||
await userEvent.click(within(nav).getByText("第一问"));
|
||||
fireEvent.mouseEnter(nav.firstElementChild!);
|
||||
fireEvent.mouseEnter(nav.querySelector("[data-outline-dot]")!);
|
||||
await userEvent.click(within(nav).getByText("第二问"));
|
||||
|
||||
expect(assignedTops).toEqual([100, 360]);
|
||||
@@ -506,7 +506,7 @@ describe("聊天视图", () => {
|
||||
render(<ChatView meta={META} />);
|
||||
await waitFor(() => expect(screen.getByText("帮我修 bug")).toBeTruthy());
|
||||
const nav = await screen.findByRole("navigation", { name: "提问大纲" });
|
||||
fireEvent.mouseEnter(nav.firstElementChild!);
|
||||
fireEvent.mouseEnter(nav.querySelector("[data-outline-dot]")!);
|
||||
// DOM 里只有 seq=1 的气泡(seq=9 未加载),它就是滚动跟踪的当前项
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText("第一问").closest("button")?.getAttribute("aria-current")).toBe("true"),
|
||||
|
||||
@@ -64,8 +64,12 @@ describe("OutlineNav 交互", () => {
|
||||
const onJump = vi.fn();
|
||||
render(<OutlineNav entries={entries} onJump={onJump} />);
|
||||
const nav = screen.getByRole("navigation", { name: "提问大纲" });
|
||||
expect(screen.queryByText("第一问")).toBeNull(); // 未悬停不浮面板
|
||||
expect(screen.queryByText("第一问")).toBeNull();
|
||||
fireEvent.mouseEnter(nav.firstElementChild!);
|
||||
expect(screen.queryByText("第一问")).toBeNull(); // 点列外的空白轨道不触发展开
|
||||
fireEvent.mouseEnter(nav.querySelector("[data-outline-rail]")!);
|
||||
expect(screen.queryByText("第一问")).toBeNull(); // 点列自身的 padding / gap 也不触发
|
||||
fireEvent.mouseEnter(nav.querySelector("[data-outline-dot]")!);
|
||||
expect(screen.getByText("第一问")).toBeTruthy();
|
||||
expect(screen.getByText("(空消息)")).toBeTruthy();
|
||||
fireEvent.click(screen.getByText("第一问"));
|
||||
@@ -80,27 +84,46 @@ describe("OutlineNav 交互", () => {
|
||||
[{ kind: "user", text: "刚发的提问", seq: 9 }],
|
||||
);
|
||||
render(<OutlineNav entries={merged} onJump={onJump} />);
|
||||
fireEvent.mouseEnter(screen.getByRole("navigation", { name: "提问大纲" }).firstElementChild!);
|
||||
fireEvent.mouseEnter(screen.getByRole("navigation", { name: "提问大纲" }).querySelector("[data-outline-dot]")!);
|
||||
fireEvent.click(screen.getByText("刚发的提问"));
|
||||
expect(onJump).toHaveBeenCalledWith(9, undefined);
|
||||
});
|
||||
|
||||
it("activeSeq 当前项:面板内该条 aria-current=true,其余不带", () => {
|
||||
render(<OutlineNav entries={entries} activeSeq={5} onJump={() => {}} />);
|
||||
fireEvent.mouseEnter(screen.getByRole("navigation", { name: "提问大纲" }).firstElementChild!);
|
||||
fireEvent.mouseEnter(screen.getByRole("navigation", { name: "提问大纲" }).querySelector("[data-outline-dot]")!);
|
||||
expect(screen.getByText("(空消息)").closest("button")?.getAttribute("aria-current")).toBe("true");
|
||||
expect(screen.getByText("第一问").closest("button")?.getAttribute("aria-current")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// 限高/滚动的载体是结构契约,不是样式偏好:挂错一层就整列溢出到 composer
|
||||
// 之下(2026-08-07 用户报障)。jsdom 量不了几何,这里钉「挂在谁身上」。
|
||||
describe("点列限高的载体", () => {
|
||||
// 点列仍保留限高,极小窗口下不会溢出到 composer;长会话则只展示
|
||||
// 当前轮附近的点,完整条目保留在展开面板中。
|
||||
describe("长对话点列压缩", () => {
|
||||
const many = outlineEntriesOf(
|
||||
Array.from({ length: 40 }, (_, i) => ({ seq: i + 1, offset: i * 10, text: `问题 ${i + 1}` })),
|
||||
[],
|
||||
);
|
||||
|
||||
it("常驻点列最多显示 12 条;无当前项时展示最新条目,展开面板仍保留全部", () => {
|
||||
const { container } = render(<OutlineNav entries={many} onJump={() => {}} />);
|
||||
const dots = [...container.querySelectorAll("[data-outline-dot]")];
|
||||
expect(dots).toHaveLength(12);
|
||||
expect(dots.map((dot) => dot.getAttribute("data-outline-dot"))).toEqual(
|
||||
Array.from({ length: 12 }, (_, i) => String(i + 29)),
|
||||
);
|
||||
|
||||
fireEvent.mouseEnter(container.querySelector("[data-outline-dot]")!);
|
||||
expect(container.querySelectorAll(".dropdown-content li")).toHaveLength(40);
|
||||
});
|
||||
|
||||
it("有当前项时点列围绕当前轮截取", () => {
|
||||
const { container } = render(<OutlineNav entries={many} activeSeq={20} onJump={() => {}} />);
|
||||
const dots = [...container.querySelectorAll("[data-outline-dot]")];
|
||||
expect(dots).toHaveLength(12);
|
||||
expect(dots.some((dot) => dot.getAttribute("data-outline-dot") === "20")).toBe(true);
|
||||
});
|
||||
|
||||
it("限高 + 纵滚 + 藏滚条都在点列自身,dropdown 外壳不带 overflow", () => {
|
||||
const { container } = render(<OutlineNav entries={many} onJump={() => {}} />);
|
||||
const shell = container.querySelector(".dropdown") as HTMLElement;
|
||||
@@ -114,7 +137,7 @@ describe("点列限高的载体", () => {
|
||||
expect(shell.className).toContain("h-full");
|
||||
expect(rail.className).toContain("max-h-full");
|
||||
expect(rail.className).not.toMatch(/vh/);
|
||||
fireEvent.mouseEnter(shell);
|
||||
fireEvent.mouseEnter(rail.querySelector("[data-outline-dot]")!);
|
||||
const panel = container.querySelector(".dropdown-content") as HTMLElement;
|
||||
expect(panel.className).toContain("max-h-full");
|
||||
expect(panel.className).not.toMatch(/vh/);
|
||||
|
||||
@@ -15,6 +15,7 @@ import type { ChatItem } from "@/lib/protocol/types";
|
||||
import { fmtClock } from "@/lib/util/fmt";
|
||||
|
||||
const MAX_LABEL = 60;
|
||||
const MAX_RAIL_DOTS = 12;
|
||||
|
||||
export interface OutlineEntry {
|
||||
/** 与 UserItem.seq / DOM 的 data-user-seq 对表。 */
|
||||
@@ -106,6 +107,14 @@ export const OutlineNav = memo(function OutlineNav({
|
||||
e.label ||
|
||||
(e.attCount > 0 ? t("chat.outline.attachments", { count: e.attCount }) : t("chat.outline.emptyMsg"));
|
||||
|
||||
const activeIndex = entries.findIndex((e) => e.seq === activeSeq);
|
||||
const railCenter = activeIndex >= 0 ? activeIndex : entries.length - 1;
|
||||
const railStart = Math.min(
|
||||
Math.max(0, railCenter - Math.floor(MAX_RAIL_DOTS / 2)),
|
||||
entries.length - Math.min(entries.length, MAX_RAIL_DOTS),
|
||||
);
|
||||
const railEntries = entries.slice(railStart, railStart + MAX_RAIL_DOTS);
|
||||
|
||||
return (
|
||||
<nav
|
||||
aria-label={t("chat.outline.label")}
|
||||
@@ -116,13 +125,21 @@ export const OutlineNav = memo(function OutlineNav({
|
||||
受消息区域约束,不再拿 viewport 高度估算。 */}
|
||||
<div
|
||||
className={`dropdown dropdown-right dropdown-center pointer-events-auto flex h-full items-center ${open ? "dropdown-open" : ""}`}
|
||||
onMouseEnter={() => setOpen(true)}
|
||||
onMouseLeave={() => setOpen(false)}
|
||||
>
|
||||
<div className="mc-no-scrollbar flex max-h-full flex-col items-center gap-1.5 overflow-x-hidden overflow-y-auto px-1.5 py-2">
|
||||
{entries.map((e) => (
|
||||
<div
|
||||
data-outline-rail
|
||||
className="mc-no-scrollbar flex max-h-full flex-col items-center gap-1.5 overflow-x-hidden overflow-y-auto px-1.5 py-2"
|
||||
>
|
||||
{railEntries.map((e) => (
|
||||
// 当前点满不透明度、其余压暗:只用透明度差表达「在哪」,不换色
|
||||
<span key={e.seq} aria-hidden className={`status shrink-0${e.seq === activeSeq ? "" : " opacity-40"}`} />
|
||||
<span
|
||||
key={e.seq}
|
||||
data-outline-dot={e.seq}
|
||||
aria-hidden
|
||||
className={`status shrink-0${e.seq === activeSeq ? "" : " opacity-40"}`}
|
||||
onMouseEnter={() => setOpen(true)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{open && (
|
||||
|
||||
@@ -51,9 +51,12 @@ describe("anchorScrollTop(恢复:锚点 → scrollTop,越界钳制)", () => {
|
||||
});
|
||||
|
||||
describe("outlineActiveSeq(视口当前提问判定,移植旧 outline.tsx)", () => {
|
||||
it("空列表/全部还在顶线之下回 null", () => {
|
||||
it("空列表回 null", () => {
|
||||
expect(outlineActiveSeq([], 0)).toBeNull();
|
||||
expect(outlineActiveSeq([{ seq: 1, top: 100 }], 0)).toBeNull();
|
||||
});
|
||||
|
||||
it("滚动到顶部且首条受容器内边距下移时,首条仍是当前项", () => {
|
||||
expect(outlineActiveSeq([{ seq: 1, top: 48 }], 0)).toBe(1);
|
||||
});
|
||||
|
||||
it("取顶线之上最后一条的 seq", () => {
|
||||
|
||||
@@ -58,12 +58,13 @@ export const OUTLINE_JUMP_INSET = 12;
|
||||
|
||||
/** 视口当前所在的提问 = 视口顶线(含 INSET)之上最后一条条目的 seq;
|
||||
* 给布局的亚像素取整留 1px 余量,避免恰好对齐时来回跳。seqTops 按文档序
|
||||
* 传入;无命中(列表为空/全部还在顶线之下)回 null。 */
|
||||
* 传入;若首条因容器内边距/顶部控件仍在顶线之下,它就是当前项;仅空列表
|
||||
* 回 null。 */
|
||||
export function outlineActiveSeq(seqTops: Array<{ seq: number; top: number }>, viewportTop: number): number | null {
|
||||
let seq: number | null = null;
|
||||
for (const item of seqTops) {
|
||||
if (item.top - viewportTop > OUTLINE_JUMP_INSET + 1) break;
|
||||
seq = item.seq;
|
||||
}
|
||||
return seq;
|
||||
return seq ?? seqTops[0]?.seq ?? null;
|
||||
}
|
||||
Reference in new issue
Block a user