fix(ui/chat): fix dock drag/resize bounds and dynamic slash command loader

This commit is contained in:
sam committed 2026-11-25 23:34:16 +11:00
1 parent 7904ccdfe0
commit 4b399e44aa
5 files changed
+91 -23

No files matched your search

+14 -6
View File
@@ -164,17 +164,25 @@ async function searchWorkflows(query: string): Promise<MenuEntry[]> {
}));
}
function searchCommands(query: string): MenuEntry[] {
const q = query.trim().toLowerCase();
return commandSpecs.value
.filter((spec) => `${spec.command} ${spec.description ?? ""}`.toLowerCase().includes(q))
.slice(0, 8)
.map((spec) => ({
value: spec.command,
label: spec.command,
keywords: spec.description ? [spec.description] : [],
detail: spec.description || spec.usage || "",
}));
}
const triggers = computed<TriggerDefinition[]>(() => [
{
char: "/",
boundary: "start",
type: "command",
items: commandSpecs.value.map((spec) => ({
value: spec.command,
label: spec.command,
keywords: spec.description ? [spec.description] : [],
detail: spec.description || spec.usage || "",
})),
items: searchCommands,
},
{
char: "@",
+21 -10
View File
@@ -28,7 +28,6 @@ import {
SWIPE,
barPlacement,
fitRect,
BAR_W,
INSET,
handleOrientation,
handleValue,
@@ -120,9 +119,7 @@ const winRect = computed<Rect>(() => {
if (pinned.value) {
return { x: mode.value === "left" ? 0 : vw.value - pinW.value, y: 0, w: pinW.value, h: vh.value };
}
// Opening the window never narrows it below the minimised bar.
const minW = Math.min(BAR_W, vw.value - INSET * 2);
return fitRect({ ...layout.value, w: Math.max(layout.value.w, minW) }, vw.value, vh.value);
return fitRect(layout.value, vw.value, vh.value);
});
// The part of the layout viewport the on-screen keyboard covers, and the height
@@ -254,7 +251,16 @@ const bar = ref<HTMLElement | null>(null);
function onDragSurface(target: HTMLElement): boolean {
const surface = expanded.value ? header.value : bar.value;
if (!surface?.contains(target)) return false;
return !target.closest("button, a, input, select, textarea, [role=combobox], [role=separator]") || !!target.closest("[data-move-handle]");
return (
!target.closest('button, a, input, select, textarea, [role="combobox"], [role="separator"], [role="textbox"], [contenteditable="true"], [contenteditable=""]') ||
!!target.closest("[data-move-handle]")
);
}
function onBarFocusIn(event: FocusEvent): void {
const target = event.target as HTMLElement | null;
if (target?.closest("[data-move-handle]")) return;
expanded.value = true;
}
// Pointer travel before a press becomes a drag, so a click or a double-click
@@ -264,7 +270,7 @@ useDraggable(dock, {
disabled: () => !desktop.value,
onStart: (_, e) => {
if (!e.isPrimary || !onDragSurface(e.target as HTMLElement)) return false;
drag = { origin: { ...winRect.value }, x0: e.clientX, y0: e.clientY, moved: false, snap: null };
drag = { origin: resizeOrigin(), x0: e.clientX, y0: e.clientY, moved: false, snap: null };
},
onMove: (_, e) => {
if (!drag) return;
@@ -273,9 +279,14 @@ useDraggable(dock, {
if (!drag.moved && Math.hypot(dx, dy) < DRAG_START) return;
drag.moved = true;
dragging.value = true;
if (!expanded.value) {
const nextX = Math.min(Math.max(drag.origin.x + dx, INSET), Math.max(INSET, vw.value - drag.origin.w - INSET));
layout.value = { ...layout.value, mode: "float", x: nextX };
return;
}
const next = fitRect({ ...drag.origin, x: drag.origin.x + dx, y: drag.origin.y + dy }, vw.value, vh.value);
layout.value = { ...layout.value, mode: "float", x: next.x, y: next.y, w: next.w, h: next.h };
drag.snap = expanded.value ? snapEdge(e.clientX, vw.value) : null;
drag.snap = snapEdge(e.clientX, vw.value);
snapTarget.value = drag.snap;
},
onEnd: (_, e) => {
@@ -368,8 +379,8 @@ const DIR_LABEL: Record<ResizeDir, string> = {
se: "bottom right",
sw: "bottom left",
};
// The minimised bar keeps its height, so only its width edges resize it.
const visibleDirs = computed<ResizeDir[]>(() => (expanded.value ? [...RESIZE_DIRS] : ["e", "w"]));
// Only the expanded floating window resizes; the minimised bar is move-only.
const visibleDirs = computed<ResizeDir[]>(() => (expanded.value ? [...RESIZE_DIRS] : []));
// The rectangle a resize starts from. Minimised, the bar can sit at an edge
// rather than at the stored x, so its rendered x and width are the origin, or
@@ -534,7 +545,7 @@ function onPinKey(event: KeyboardEvent): void {
>
<ChatTranscript />
</div>
<div ref="bar" class="touch-none" @focusin="expanded = true">
<div ref="bar" class="touch-none" @focusin="onBarFocusIn">
<ChatComposer :open="false" :flat="!expanded">
<template v-if="!expanded && desktop" #start>
<Tooltip>
+9 -5
View File
@@ -94,13 +94,17 @@ export function normalizeLayout(raw: unknown, vw: number, vh: number): DockLayou
/** Resize a rectangle from one of the eight edges/corners by a pointer delta. */
export function resizeRect(origin: Rect, dir: ResizeDir, dx: number, dy: number, vw: number, vh: number): Rect {
const rect = { ...origin };
const minW = Math.min(MIN_W, Math.max(1, vw - INSET * 2));
const minH = Math.min(MIN_H, Math.max(1, vh - INSET * 2));
if (dir.includes("e")) rect.w = clamp(origin.w + dx, minW, Math.max(minW, vw - origin.x - INSET));
const availW = Math.max(1, vw - INSET * 2);
const availH = Math.max(1, vh - INSET * 2);
const minW = Math.min(MIN_W, availW);
const maxW = Math.min(MAX_W, availW);
const minH = Math.min(MIN_H, availH);
if (dir.includes("e")) rect.w = clamp(origin.w + dx, minW, Math.min(maxW, Math.max(minW, vw - origin.x - INSET)));
if (dir.includes("s")) rect.h = clamp(origin.h + dy, minH, Math.max(minH, vh - origin.y - INSET));
if (dir.includes("w")) {
rect.x = clamp(origin.x + dx, INSET, origin.x + origin.w - minW);
rect.w = origin.x + origin.w - rect.x;
const right = origin.x + origin.w;
rect.x = clamp(origin.x + dx, Math.max(INSET, right - maxW), right - minW);
rect.w = right - rect.x;
}
if (dir.includes("n")) {
rect.y = clamp(origin.y + dy, INSET, origin.y + origin.h - minH);
+9 -2
View File
@@ -4,6 +4,7 @@ import test from "node:test";
import {
DOCK_STORAGE_KEY,
LEGACY_DOCK_STORAGE_KEY,
MAX_W,
MIN_H,
MIN_W,
barPlacement,
@@ -105,13 +106,19 @@ test("all eight edges and corners resize the rectangle in their own direction",
}
});
test("resize never collapses the window below the minimum or pushes it off screen", () => {
test("resize never collapses the window below the minimum, exceeds the maximum, or pushes it off screen", () => {
const origin = { x: 100, y: 100, w: 400, h: 300 };
assert.deepEqual(resizeRect(origin, "e", -9999, 0, VW, VH), { x: 100, y: 100, w: MIN_W, h: 300 });
assert.deepEqual(resizeRect(origin, "s", 0, -9999, VW, VH), { x: 100, y: 100, w: 400, h: MIN_H });
assert.deepEqual(resizeRect(origin, "w", 9999, 0, VW, VH), { x: 100 + 400 - MIN_W, y: 100, w: MIN_W, h: 300 });
assert.deepEqual(resizeRect(origin, "n", 0, 9999, VW, VH), { x: 100, y: 100 + 300 - MIN_H, w: 400, h: MIN_H });
assert.deepEqual(resizeRect({ x: 0, y: 0, w: 400, h: 300 }, "e", 99999, 0, VW, VH), { x: 0, y: 0, w: VW - 8, h: 300 });
assert.deepEqual(resizeRect({ x: 0, y: 0, w: 400, h: 300 }, "e", 99999, 0, VW, VH), { x: 0, y: 0, w: MAX_W, h: 300 });
assert.deepEqual(resizeRect({ x: 500, y: 100, w: 400, h: 300 }, "w", -9999, 0, VW, VH), {
x: 500 + 400 - MAX_W,
y: 100,
w: MAX_W,
h: 300,
});
assert.deepEqual(resizeRect({ x: 0, y: 0, w: 400, h: 300 }, "s", 0, 99999, VW, VH), { x: 0, y: 0, w: 400, h: VH - 8 });
});
+38
View File
@@ -199,12 +199,17 @@ test("chat More menu opens on screen and its items run", { timeout: 90000 }, asy
const hr = handle.getBoundingClientRect();
const er = editor.getBoundingClientRect();
const sr = show.getBoundingClientRect();
const dr = document.querySelector('aside[aria-label="Chat with Archie"]').getBoundingClientRect();
const placeholder = getComputedStyle(editor, "::before").content;
return {
ready: true,
handleMidX: hr.x + hr.width / 2,
handleMidY: hr.y + hr.height / 2,
editorMidY: er.y + er.height / 2,
showMidY: sr.y + sr.height / 2,
dockLeft: dr.left,
dockTop: dr.top,
resizeCount: document.querySelectorAll('[data-resize]').length,
horizontalOrder: hr.right <= er.left + 1 && er.right <= sr.left + 1,
placeholder,
};
@@ -214,6 +219,7 @@ test("chat More menu opens on screen and its items run", { timeout: 90000 }, asy
return { ready: false };
})()`);
assert.equal(collapsed.ready, true, "the collapsed chat dock rendered");
assert.equal(collapsed.resizeCount, 0, "minimised chat dock renders no resize handles");
assert.equal(collapsed.horizontalOrder, true, `minimised composer controls stay on one horizontal row, got ${JSON.stringify(collapsed)}`);
assert.ok(
Math.abs(collapsed.handleMidY - collapsed.editorMidY) < 8 && Math.abs(collapsed.showMidY - collapsed.editorMidY) < 8,
@@ -224,6 +230,20 @@ test("chat More menu opens on screen and its items run", { timeout: 90000 }, asy
`empty composer shows its placeholder, got ${JSON.stringify(collapsed.placeholder)}`,
);
// Drag the collapsed move handle left: the dock moves horizontally without expanding or jumping.
await cdp.send("Input.dispatchMouseEvent", { type: "mousePressed", x: collapsed.handleMidX, y: collapsed.handleMidY, button: "left", clickCount: 1 });
for (const step of [20, 60, 100]) {
await cdp.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: collapsed.handleMidX - step, y: collapsed.handleMidY - 20, button: "left", buttons: 1 });
}
await cdp.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: collapsed.handleMidX - 100, y: collapsed.handleMidY - 20, button: "left", clickCount: 1 });
const afterDrag = await cdp.evaluate(`(() => {
const dr = document.querySelector('aside[aria-label="Chat with Archie"]').getBoundingClientRect();
return { left: dr.left, top: dr.top, expanded: !!document.querySelector('button[aria-label="Hide conversation"]') };
})()`);
assert.equal(afterDrag.expanded, false, "dragging the minimised move handle does not expand the dock");
assert.ok(Math.abs(afterDrag.left - (collapsed.dockLeft - 100)) <= 2, `minimised bar moved -100px horizontally, got ${JSON.stringify(afterDrag)} from ${collapsed.dockLeft}`);
assert.ok(Math.abs(afterDrag.top - collapsed.dockTop) <= 2, `minimised bar stayed pinned vertically, got ${JSON.stringify(afterDrag)} from ${collapsed.dockTop}`);
await cdp.evaluate(`(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
document.querySelector('button[aria-label="Show conversation"]').click();
@@ -231,6 +251,24 @@ test("chat More menu opens on screen and its items run", { timeout: 90000 }, asy
return !!document.querySelector('button[aria-label="More"]');
})()`).then((expanded: unknown) => assert.equal(expanded, true, "the chat dock expanded and rendered the More button"));
// Dragging the expanded west resize handle past MAX_W keeps the right edge pinned (no sliding).
const beforeW = await cdp.evaluate(`(() => {
const w = document.querySelector('[data-resize="w"]').getBoundingClientRect();
const d = document.querySelector('aside[aria-label="Chat with Archie"]').getBoundingClientRect();
return { wx: w.x + w.width / 2, wy: w.y + w.height / 2, right: d.right, width: d.width };
})()`);
await cdp.send("Input.dispatchMouseEvent", { type: "mousePressed", x: beforeW.wx, y: beforeW.wy, button: "left", clickCount: 1 });
for (const step of [100, 250, 450]) {
await cdp.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: beforeW.wx - step, y: beforeW.wy, button: "left", buttons: 1 });
}
await cdp.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: beforeW.wx - 450, y: beforeW.wy, button: "left", clickCount: 1 });
const afterW = await cdp.evaluate(`(() => {
const d = document.querySelector('aside[aria-label="Chat with Archie"]').getBoundingClientRect();
return { right: d.right, width: d.width };
})()`);
assert.ok(Math.abs(afterW.right - beforeW.right) <= 2, `west resize past MAX_W keeps right edge pinned, got ${JSON.stringify(afterW)} vs ${JSON.stringify(beforeW)}`);
assert.ok(afterW.width <= 720 + 1, `west resize caps width at MAX_W, got ${afterW.width}`);
// Pick the open conversation first, so the menu's actions have a
// session to act on.
await cdp.evaluate(`(() => {