Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Train fix (#7885): no extra buttons; a selection becomes a highlight as the pointer lifts

milind-sonic2367fd860bc
diff --git a/scripts/testing/page-point-highlight-ui.e2e.test.ts b/scripts/testing/page-point-highlight-ui.e2e.test.ts
index c5bd4ede3b..85adbfb0a0 100644
--- a/scripts/testing/page-point-highlight-ui.e2e.test.ts
+++ b/scripts/testing/page-point-highlight-ui.e2e.test.ts
@@ -96,7 +96,7 @@ type Report = {
await expect.poll(() => evaluate(`Boolean(document.querySelector('[data-page-fullscreen] iframe') && window.__pointReport)`), { timeout: 30_000 }).toBe(true);
const frameBox = () => evaluate(`(() => { const r = document.querySelector('[data-page-fullscreen] iframe').getBoundingClientRect(); return { left: r.left, top: r.top }; })()`) as Promise<{ left: number; top: number }>;
const report = () => evaluate("window.__pointReport") as Promise<Report>;
- const drag = async () => {
+ const drag = async (kept = true) => {
const box = await frameBox();
const { phrase, hits } = await report();
expect(hits).toEqual(["phrase", "phrase"]);
@@ -105,7 +105,8 @@ type Report = {
await mouse("down");
await mouse("move", String(Math.round(box.left + phrase.right - 1)), String(y), "--steps", "12");
await mouse("up");
- await expect.poll(report, { timeout: 10_000 }).toMatchObject({
+ // In Point mode the page takes the selection as a highlight at once, so it is not left selected.
+ if (kept) await expect.poll(report, { timeout: 10_000 }).toMatchObject({
selected: "Selected phrase", moves: expect.arrayContaining([expect.objectContaining({ buttons: 1, target: "phrase", trusted: true })]),
});
};
@@ -119,9 +120,8 @@ type Report = {
await ui("click", "--name", "Point");
await expect.poll(() => evaluate(`document.querySelector('[data-page-fullscreen] button[aria-pressed=true]')?.textContent.trim()`)).toBe("Point");
await expect.poll(async () => (await report()).cursor, { timeout: 10_000 }).toBe("crosshair");
- await drag();
- await expect.poll(() => evaluate(`![...document.querySelectorAll('[data-page-fullscreen] button')].find(b => b.textContent.trim() === 'Highlight selection')?.disabled`)).toBe(true);
- await ui("click", "--name", "Highlight selection");
+ // In Point mode a selection becomes a highlight as the pointer lifts; there is no button for it.
+ await drag(false);
await expect.poll(() => evaluate(`document.querySelector('[data-pointed-chip]')?.textContent`), { timeout: 10_000 }).toContain("Selected phrase");
await expect.poll(async () => (await report()).highlights, { timeout: 10_000 }).toEqual(["Selected phrase"]);
await expect.poll(async () => (await report()).marks, { timeout: 10_000 }).toEqual([{ number: "1", display: "block" }]);
@@ -157,7 +157,8 @@ type Report = {
console.log(`Page point screenshot: ${path}`);
}
}
- await ui("click", "--name", "Clear all");
+ await ui("click", "--name", "Remove “Selected phrase”");
+ await ui("click", "--name", "Remove “Pin target”");
await expect.poll(() => evaluate("document.querySelectorAll('[data-pointed-chip]').length")).toBe(0);
await expect.poll(async () => (await report()).marks, { timeout: 10_000 }).toEqual([]);
await expect.poll(async () => (await report()).highlights, { timeout: 10_000 }).toBeNull();
diff --git a/shared/app-frame/point.ts b/shared/app-frame/point.ts
index ea25f4c797..9813d1c825 100644
--- a/shared/app-frame/point.ts
+++ b/shared/app-frame/point.ts
@@ -446,6 +446,11 @@ export const APP_POINT_SOURCE = `(function () {
var element = pickable(event.target);
if (element && element !== current) { current = element; place(element); }
}, true);
+ // Text selected while Point is on becomes a highlight as the pointer lifts, so no button is needed; Enter does the same.
+ // Registered before the listeners below, which stop the event for everything after them.
+ window.addEventListener("mouseup", function () {
+ if (on) setTimeout(function () { if (on && selectionOf()) highlightSelection(); }, 0);
+ }, true);
["pointerdown", "mousedown", "pointerup", "mouseup", "touchstart", "selectstart"].forEach(function (type) {
window.addEventListener(type, function (event) {
if (!on) return;
diff --git a/src/components/app/PageTools.test.ts b/src/components/app/PageTools.test.ts
index e2a529c431..55e044fad5 100644
--- a/src/components/app/PageTools.test.ts
+++ b/src/components/app/PageTools.test.ts
@@ -13,7 +13,7 @@ import { MAX_WEB_PANELS } from "@/lib/web-panels";
import type { AppPayload } from "../../../shared/app";
import type { PublishedPageCard } from "../../../shared/published-page";
import { botHtmlDocument } from "../../../shared/app-frame/document";
-import { highlightSelectionMessage, marksMessage, POINT_LIMITS, POINT_SELECTION_METHOD, POINTED_METHOD } from "../../../shared/app-frame/point";
+import { marksMessage, POINT_LIMITS, POINT_SELECTION_METHOD, POINTED_METHOD } from "../../../shared/app-frame/point";
import { createAppPool, type AppPool } from "./app-pool";
import { AppMessage, forgetAppRows } from "./AppMessage";
import { PAGE_HEIGHT } from "./PageTools";
@@ -133,7 +133,7 @@ describe("a bot's page in the chat", () => {
expect(chips()).toEqual([]);
await click("Point", card());
expect(posted).toHaveBeenCalledWith({ jsonrpc: "2.0", method: "mausbot/point", params: { on: true } }, "*");
- expect(card().textContent).toContain("select text and choose Highlight selection");
+ expect(card().textContent).toContain("or select text, to point at it");
await fromFrame(PICK, window);
expect(chips()).toEqual([]);
await fromFrame(PICK, inlineFrame().contentWindow);
@@ -156,15 +156,14 @@ describe("a bot's page in the chat", () => {
const page = payload({ doc: "d1", rev: 1, history: ["d0"] });
await render(row(page));
await click("Point", card());
- const select = { jsonrpc: "2.0", method: POINT_SELECTION_METHOD, params: { state: "ready" } };
- const highlight = button("Highlight selection", card());
+ // A selection becomes a highlight in the page itself as the pointer lifts: there is no button for it here.
+ const tooLong = { jsonrpc: "2.0", method: POINT_SELECTION_METHOD, params: { state: "too-long" } };
const posted = vi.spyOn(inlineFrame().contentWindow!, "postMessage").mockImplementation(() => {});
- await fromFrame(select, window);
- expect(highlight.disabled).toBe(true);
- await fromFrame(select, inlineFrame().contentWindow);
- expect(highlight.disabled).toBe(false);
- await click("Highlight selection", card());
- expect(posted).toHaveBeenCalledWith(highlightSelectionMessage(), "*");
+ expect(button("Highlight selection", card())).toBeUndefined();
+ await fromFrame(tooLong, window);
+ expect(card().textContent).not.toContain("too long");
+ await fromFrame(tooLong, inlineFrame().contentWindow);
+ expect(card().textContent).toContain("This selection is too long");
const first = { start: 0, end: 2, fingerprint: 7 };
const second = { start: 6, end: 8, fingerprint: 7 };
const { selector } = PICK.params;
@@ -198,8 +197,7 @@ describe("a bot's page in the chat", () => {
expect(sent.pointed).toMatchObject([{ selector }, { selector, rev: 1, text: "42", range: second, note: "Wrong total" }]);
expect(newer).toHaveBeenLastCalledWith(marksMessage([]), "*");
await act(async () => { sent.restore(); });
- await click("Clear all", host);
- expect(newer).toHaveBeenLastCalledWith(marksMessage([]), "*");
+ expect(newer).toHaveBeenLastCalledWith(marksMessage([selector, { selector, range: second }]), "*");
});
it("sends Point and the numbered outlines again to the frame a reload puts in place", async () => {
@@ -336,16 +334,6 @@ describe("pointed chips", () => {
expect(kept[0]).toBe("s0");
});
- it("shows the count and clears only this conversation's points", () => {
- for (let n = 0; n < 55; n++) addPointedChip("t1", chip(`s${n}`));
- addPointedChip("t2", chip("other"));
- act(() => root.render(createElement(PointedChips, { threadId: "t1" })));
- expect(host.textContent).toContain("55 points");
- act(() => button("Clear all", host).click());
- expect(takePointedChips("t1")).toBeNull();
- expect(takePointedChips("t2")!.pointed).toHaveLength(1);
- });
-
it("carry the person's note on a part, trimmed and clipped, and keep it when the same part is picked again", () => {
for (const selector of ["a", "b"]) addPointedChip("t1", chip(selector));
act(() => root.render(createElement(PointedChips, { threadId: "t1" })));
diff --git a/src/components/app/PageTools.tsx b/src/components/app/PageTools.tsx
index 0739d91dcd..e1d1c78bf1 100644
--- a/src/components/app/PageTools.tsx
+++ b/src/components/app/PageTools.tsx
@@ -13,7 +13,7 @@ import { addPointedChip, usePointedChips } from "@/lib/pointed-chips";
import { latestWebPanels, setWebPanels, useWebPanels } from "@/lib/web-panel-preferences";
import { findPinnedPage, MAX_WEB_PANELS, togglePinnedPage, type PinnedChatPage } from "@/lib/web-panels";
import type { AppDocument, AppPayload } from "../../../shared/app";
-import { highlightSelectionMessage, marksMessage, pointMessage, readPointEvent, type PointMark, type PointSelectionState } from "../../../shared/app-frame/point";
+import { marksMessage, pointMessage, readPointEvent, type PointMark, type PointSelectionState } from "../../../shared/app-frame/point";
import type { PublishedPageCard } from "../../../shared/published-page";
import { canonicalDownloadFilename } from "../AttachmentPreview";
import { appDownloadPath, publishAppPage, unpublishPage } from "./app-api";
@@ -197,9 +197,6 @@ export function usePagePoint(args: { frame(): HTMLIFrameElement | null | undefin
return {
pointing, selection: args.ready ? selection : "none" as const,
toggle: () => set(!on.current), stop: () => { if (on.current) set(false); },
- highlight: () => {
- if (on.current && latest.current.ready) latest.current.frame()?.contentWindow?.postMessage(highlightSelectionMessage(), "*");
- },
};
}
@@ -322,13 +319,7 @@ export function PageNotes({ version, point, share, save, room, className }: Pick
);
}
if (save.reason) rows.push(<p key="save" role="alert" dir="auto" className="px-1 text-[13px] text-danger">{save.reason}</p>);
- if (point.pointing) rows.push(
- <div key="hint" className="flex flex-wrap items-center gap-2 rounded-xl bg-accent/10 px-3 py-2 text-[13px] text-ink">
- <span role="status" className="min-w-0 flex-1">{t(point.selection === "too-long" ? "chat.preview.pointSelectionTooLong" : "chat.preview.pointSelectionHint")}</span>
- <button type="button" className={cn(ASK_CHIP, ASK_CHIP_IDLE, "disabled:opacity-50")} disabled={point.selection !== "ready"}
- onPointerDown={(event) => event.preventDefault()} onClick={point.highlight}>{t("chat.preview.highlightSelection")}</button>
- </div>,
- );
+ if (point.pointing) rows.push(<div key="hint" role="status" className="rounded-2xl bg-accent/10 px-3 py-2 text-[13px] text-ink">{t(point.selection === "too-long" ? "chat.preview.pointSelectionTooLong" : "chat.preview.pointSelectionHint")}</div>);
return rows.length ? <div className={cn("flex flex-col gap-2", className)}>{rows}</div> : null;
}
diff --git a/src/components/app/PointedChips.tsx b/src/components/app/PointedChips.tsx
index 25ea2b1ff4..4bcfd2a4aa 100644
--- a/src/components/app/PointedChips.tsx
+++ b/src/components/app/PointedChips.tsx
@@ -1,7 +1,7 @@
import { useRef, useState } from "react";
import { Crosshair, Highlighter, StickyNote, X } from "lucide-react";
import { t } from "@/lib/i18n";
-import { clearPointedChips, removePointedChip, setPointedNote, usePointedChips } from "@/lib/pointed-chips";
+import { removePointedChip, setPointedNote, usePointedChips } from "@/lib/pointed-chips";
import { pointedLabel } from "../../../shared/app-frame/point";
/** The parts of a page the person pointed at, waiting to go with their next message. Each is numbered as its outline
@@ -15,10 +15,6 @@ export function PointedChips({ threadId }: { threadId: string }) {
const openLabel = open ? pointedLabel(open) ?? t("chat.preview.pointedPart") : "";
return (
<div data-pointed-chips className="mb-2">
- <div className="mb-1 flex items-center gap-2 text-[12px] text-ink-secondary">
- <span>{chips.length === 1 ? t("chat.preview.onePoint") : t("chat.preview.pointCount", { count: chips.length })}</span>
- <button type="button" onClick={() => { clearPointedChips(threadId); setEditing(null); }} className="hover:text-ink hover:underline">{t("chat.preview.clearPoints")}</button>
- </div>
<div ref={list} className="flex max-h-32 flex-wrap gap-1.5 overflow-y-auto">
{chips.map((chip, index) => {
const label = pointedLabel(chip) ?? t("chat.preview.pointedPart");
diff --git a/src/lib/pointed-chips.ts b/src/lib/pointed-chips.ts
index fa2cfaeda6..2158fd7936 100644
--- a/src/lib/pointed-chips.ts
+++ b/src/lib/pointed-chips.ts
@@ -78,12 +78,6 @@ export function takePointedChips(threadId: string): { pointed: PointedElement[];
};
}
-export function clearPointedChips(threadId: string): void {
- if (!chips[threadId]) return;
- const { [threadId]: _cleared, ...rest } = chips;
- set(rest);
-}
-
export function forgetPointedChips(): void {
set({});
}