fix(webui): preserve prompt rail markers before long answers

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-10 15:33:35 +08:00
1 parent a4140dac25
commit f39702f1cf
2 files changed
+44 -34

No files matched your search

+11 -34
View File
@@ -40,13 +40,12 @@ interface PromptMarker {
topPercent: number;
}
const MIN_PROMPTS_FOR_RAIL = 3;
const MIN_PROMPTS_FOR_RAIL = 2;
const RAIL_MIN_SCROLL_RANGE_PX = 80;
const DENSE_PROMPT_THRESHOLD = 30;
const DENSE_BUCKET_HEIGHT_PX = 12;
const DENSE_BUCKET_FALLBACK_COUNT = 32;
const DENSE_BUCKET_MAX_COUNT = 42;
const MARKER_MIN_GAP_PX = 9;
const MARKER_BASE_WIDTH_PX = 9;
const MARKER_STACK_GAP_PX = 16;
const RAIL_FALLBACK_HEIGHT_PX = 300;
@@ -263,32 +262,14 @@ function groupPromptMarkers(
return bucketPromptMarkers(measured, railHeight);
}
const minGapPercent = railHeight > 0
? (MARKER_MIN_GAP_PX / railHeight) * 100
: 2;
const groups: PromptMarker[] = [];
for (const prompt of measured) {
const last = groups[groups.length - 1];
if (last && prompt.topPercent - last.topPercent < minGapPercent) {
last.count += 1;
last.ids.push(prompt.id);
last.label = groupedPromptLabel(last.count, prompt.label);
last.answerPreview = prompt.answerPreview;
last.preview = prompt.preview;
continue;
}
groups.push({
answerPreview: prompt.answerPreview,
count: 1,
ids: [prompt.id],
label: prompt.label,
preview: prompt.preview,
topPercent: prompt.topPercent,
});
}
return groups;
return measured.map((prompt) => ({
answerPreview: prompt.answerPreview,
count: 1,
ids: [prompt.id],
label: prompt.label,
preview: prompt.preview,
topPercent: prompt.topPercent,
}));
}
function bucketPromptMarkers(
@@ -304,12 +285,8 @@ function bucketPromptMarkers(
: DENSE_BUCKET_FALLBACK_COUNT;
const buckets = Array.from({ length: bucketCount }, () => [] as MeasuredPrompt[]);
for (const prompt of measured) {
const bucketIndex = clamp(
Math.floor((prompt.topPercent / 100) * bucketCount),
0,
bucketCount - 1,
);
for (const [index, prompt] of measured.entries()) {
const bucketIndex = Math.floor((index / measured.length) * bucketCount);
buckets[bucketIndex].push(prompt);
}
+33
View File
@@ -1819,6 +1819,39 @@ describe("ThreadViewport", () => {
expect(screen.getByLabelText("User prompt navigation")).toBeInTheDocument();
});
it.each([2, 3, 100])("keeps %i prompts navigable before a very long answer", async (count) => {
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
.mockReturnValue("started");
const { promptEls, scroller } = await renderPromptRailViewport({
messages: makeLongMessages(count),
});
Object.defineProperty(scroller, "scrollHeight", {
configurable: true,
value: 1_000_000,
});
promptEls.forEach((el, index) => {
Object.defineProperty(el, "offsetTop", { configurable: true, value: index * 40 });
});
await act(async () => {
window.dispatchEvent(new Event("resize"));
await new Promise<void>((resolve) => window.requestAnimationFrame(() => resolve()));
});
const markers = screen.getAllByRole("button", { name: /Jump to prompt:/ });
if (count < 30) {
expect(markers).toHaveLength(count);
markers.forEach((marker, index) => {
fireEvent.click(marker);
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 16));
});
} else {
expect(markers.length).toBeGreaterThan(1);
expect(markers.length).toBeLessThan(count);
}
fireEvent.click(markers[markers.length - 1]);
expect(navigateTo).toHaveBeenLastCalledWith((count - 1) * 40 - 16);
});
it("buckets dense prompt rails without rendering every prompt as a marker", async () => {
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
.mockReturnValue("started");