fix(webui): preserve prompt rail markers before long answers
This commit is contained in:
1 parent
a4140dac25
commit
f39702f1cf
2 files changed
+44
-34
No files matched your search
@@ -40,13 +40,12 @@ interface PromptMarker {
|
|||||||
topPercent: number;
|
topPercent: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MIN_PROMPTS_FOR_RAIL = 3;
|
const MIN_PROMPTS_FOR_RAIL = 2;
|
||||||
const RAIL_MIN_SCROLL_RANGE_PX = 80;
|
const RAIL_MIN_SCROLL_RANGE_PX = 80;
|
||||||
const DENSE_PROMPT_THRESHOLD = 30;
|
const DENSE_PROMPT_THRESHOLD = 30;
|
||||||
const DENSE_BUCKET_HEIGHT_PX = 12;
|
const DENSE_BUCKET_HEIGHT_PX = 12;
|
||||||
const DENSE_BUCKET_FALLBACK_COUNT = 32;
|
const DENSE_BUCKET_FALLBACK_COUNT = 32;
|
||||||
const DENSE_BUCKET_MAX_COUNT = 42;
|
const DENSE_BUCKET_MAX_COUNT = 42;
|
||||||
const MARKER_MIN_GAP_PX = 9;
|
|
||||||
const MARKER_BASE_WIDTH_PX = 9;
|
const MARKER_BASE_WIDTH_PX = 9;
|
||||||
const MARKER_STACK_GAP_PX = 16;
|
const MARKER_STACK_GAP_PX = 16;
|
||||||
const RAIL_FALLBACK_HEIGHT_PX = 300;
|
const RAIL_FALLBACK_HEIGHT_PX = 300;
|
||||||
@@ -263,32 +262,14 @@ function groupPromptMarkers(
|
|||||||
return bucketPromptMarkers(measured, railHeight);
|
return bucketPromptMarkers(measured, railHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
const minGapPercent = railHeight > 0
|
return measured.map((prompt) => ({
|
||||||
? (MARKER_MIN_GAP_PX / railHeight) * 100
|
answerPreview: prompt.answerPreview,
|
||||||
: 2;
|
count: 1,
|
||||||
const groups: PromptMarker[] = [];
|
ids: [prompt.id],
|
||||||
|
label: prompt.label,
|
||||||
for (const prompt of measured) {
|
preview: prompt.preview,
|
||||||
const last = groups[groups.length - 1];
|
topPercent: prompt.topPercent,
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bucketPromptMarkers(
|
function bucketPromptMarkers(
|
||||||
@@ -304,12 +285,8 @@ function bucketPromptMarkers(
|
|||||||
: DENSE_BUCKET_FALLBACK_COUNT;
|
: DENSE_BUCKET_FALLBACK_COUNT;
|
||||||
const buckets = Array.from({ length: bucketCount }, () => [] as MeasuredPrompt[]);
|
const buckets = Array.from({ length: bucketCount }, () => [] as MeasuredPrompt[]);
|
||||||
|
|
||||||
for (const prompt of measured) {
|
for (const [index, prompt] of measured.entries()) {
|
||||||
const bucketIndex = clamp(
|
const bucketIndex = Math.floor((index / measured.length) * bucketCount);
|
||||||
Math.floor((prompt.topPercent / 100) * bucketCount),
|
|
||||||
0,
|
|
||||||
bucketCount - 1,
|
|
||||||
);
|
|
||||||
buckets[bucketIndex].push(prompt);
|
buckets[bucketIndex].push(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1819,6 +1819,39 @@ describe("ThreadViewport", () => {
|
|||||||
expect(screen.getByLabelText("User prompt navigation")).toBeInTheDocument();
|
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 () => {
|
it("buckets dense prompt rails without rendering every prompt as a marker", async () => {
|
||||||
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
|
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
|
||||||
.mockReturnValue("started");
|
.mockReturnValue("started");
|
||||||
|
|||||||
Reference in new issue
Block a user