Skip to content

Commit 30b07ff

Browse files
saphidclaude
andcommitted
fix(web): drop the undo notice hover hold from the composer undo fix
Holding the notice while hovered is independent of Cmd+Z routing from the composer, so it is removed here (code, tests and docs) and can return as its own change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 76f07eb commit 30b07ff

6 files changed

Lines changed: 16 additions & 133 deletions

File tree

‎apps/web/src/components/sidebar/SidebarThreadUndoNotice.test.tsx‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎apps/web/src/components/sidebar/SidebarThreadUndoNotice.tsx‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import { useEffect, useRef } from "react";
32

4-
import {
5-
setThreadUndoNoticeHeld,
6-
undoLatestThreadAction,
7-
useThreadUndoNotice,
8-
} from "../../hooks/showThreadUndoNotice";
3+
import { undoLatestThreadAction, useThreadUndoNotice } from "../../hooks/showThreadUndoNotice";
94
import { shortcutLabelForCommand } from "../../keybindings";
105
import { primaryServerKeybindingsAtom } from "../../state/server";
116
import { Alert, AlertDescription } from "../ui/alert";
@@ -14,35 +9,13 @@ import { InlineButton } from "../ui/button";
149
export function SidebarThreadUndoNotice() {
1510
const notice = useThreadUndoNotice((state) => state.notice);
1611
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
17-
const held = useRef(false);
18-
const visible = notice !== null;
19-
useEffect(() => {
20-
if (!visible) return;
21-
return () => {
22-
if (held.current) {
23-
held.current = false;
24-
setThreadUndoNoticeHeld(false);
25-
}
26-
};
27-
}, [visible]);
2812

2913
if (!notice) return null;
3014
const shortcut = shortcutLabelForCommand(keybindings, "thread.undo");
3115
const noun = `${notice.action === "Discarded" ? "draft" : "thread"}${notice.count === 1 ? "" : "s"}`;
3216

3317
return (
34-
<Alert
35-
role="status"
36-
variant="sidebar"
37-
onPointerEnter={() => {
38-
held.current = true;
39-
setThreadUndoNoticeHeld(true);
40-
}}
41-
onPointerLeave={() => {
42-
held.current = false;
43-
setThreadUndoNoticeHeld(false);
44-
}}
45-
>
18+
<Alert role="status" variant="sidebar">
4619
<AlertDescription>
4720
{notice.action} {notice.count} {noun},{" "}
4821
<InlineButton onClick={undoLatestThreadAction}>

‎apps/web/src/hooks/showThreadUndoNotice.test.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"
44

55
import { toastManager } from "../components/ui/toast";
66
import {
7-
setThreadUndoNoticeHeld,
87
showThreadUndoNotice,
98
undoLatestThreadAction,
109
useThreadUndoNotice,
@@ -150,29 +149,4 @@ describe("thread undo notice", () => {
150149
expect(older).toHaveBeenCalledOnce();
151150
expect(undoLatestThreadAction()).toBe(false);
152151
});
153-
154-
it("holds the notice while hovered and restarts the full timer on leave", () => {
155-
const { options } = setup();
156-
showThreadUndoNotice(options);
157-
vi.advanceTimersByTime(4_000);
158-
setThreadUndoNoticeHeld(true);
159-
vi.advanceTimersByTime(60_000);
160-
expect(useThreadUndoNotice.getState().notice).not.toBeNull();
161-
setThreadUndoNoticeHeld(false);
162-
vi.advanceTimersByTime(4_999);
163-
expect(useThreadUndoNotice.getState().notice).not.toBeNull();
164-
vi.advanceTimersByTime(1);
165-
expect(useThreadUndoNotice.getState().notice).toBeNull();
166-
});
167-
168-
it("does not carry a hover hold over to the next notice", () => {
169-
const { options } = setup();
170-
showThreadUndoNotice(options);
171-
setThreadUndoNoticeHeld(true);
172-
void undoLatestThreadAction();
173-
expect(useThreadUndoNotice.getState().notice).toBeNull();
174-
showThreadUndoNotice({ ...options, claim: ThreadUndo.begin("pin", "env/next") });
175-
vi.advanceTimersByTime(5_000);
176-
expect(useThreadUndoNotice.getState().notice).toBeNull();
177-
});
178152
});

‎apps/web/src/hooks/showThreadUndoNotice.ts‎

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ export const useThreadUndoNotice = create<{ notice: UndoNotice | null }>(() => (
2929
// same kind share one notice and can be restored together.
3030
let liveUndos: UndoOptions[] = [];
3131
let expiry: ReturnType<typeof setTimeout> | undefined;
32-
let expiryPaused = false;
33-
const UNDO_NOTICE_TTL_MS = 5_000;
34-
35-
function expireUndos() {
36-
const expired = liveUndos;
37-
liveUndos = [];
38-
for (const { claim, commit } of expired) {
39-
claim.finish();
40-
commit?.();
41-
}
42-
refreshNotice();
43-
}
44-
45-
function scheduleExpiry() {
46-
clearTimeout(expiry);
47-
if (!expiryPaused) expiry = setTimeout(expireUndos, UNDO_NOTICE_TTL_MS);
48-
}
4932

5033
function refreshNotice() {
5134
const stale = liveUndos.filter(({ claim }) => !claim.isCurrent());
@@ -54,8 +37,6 @@ function refreshNotice() {
5437
const latest = liveUndos.at(-1);
5538
if (!latest) {
5639
clearTimeout(expiry);
57-
// The notice unmounts without a pointer-leave, so drop a stale hover hold.
58-
expiryPaused = false;
5940
useThreadUndoNotice.setState({ notice: null });
6041
return;
6142
}
@@ -119,11 +100,14 @@ export function showThreadUndoNotice(options: UndoOptions) {
119100
if (!options.claim.isCurrent()) return;
120101
liveUndos.push(options);
121102
refreshNotice();
122-
scheduleExpiry();
123-
}
124-
125-
/** Holds the notice while the pointer is over it; leaving restarts the full timer. */
126-
export function setThreadUndoNoticeHeld(held: boolean) {
127-
expiryPaused = held;
128-
if (liveUndos.length > 0) scheduleExpiry();
103+
clearTimeout(expiry);
104+
expiry = setTimeout(() => {
105+
const expired = liveUndos;
106+
liveUndos = [];
107+
for (const { claim, commit } of expired) {
108+
claim.finish();
109+
commit?.();
110+
}
111+
refreshNotice();
112+
}, 5_000);
129113
}

‎docs/user/keybindings.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ shortcut; assign one in **Settings → Keybindings**.
145145
bottom of the sidebar, such as unpin, settle, snooze, archive, or discarding a
146146
draft. Consecutive
147147
actions of the same kind undo together. The notice remains available for five
148-
seconds after the latest action, and stays up while the pointer is over it. The
149-
default shortcut skips native text fields and terminals, and preserves the
150-
composer’s edit history. An empty composer with no edits to undo does not block it.
148+
seconds after the latest action. The default shortcut skips native text fields
149+
and terminals, and preserves the composer’s edit history. An empty composer with
150+
no edits to undo does not block it.
151151

152152
`navigation.back` (`mod+[` by default) and `navigation.forward` (`mod+]`) move
153153
through the pages you have visited, like a browser's back and forward buttons.

‎docs/user/thread-sidebar.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ and worktree while you stay in the new thread composer. This requires a Git proj
4848
Pin a thread from its menu to keep it above your active work.
4949

5050
On web and desktop, unpinning, settling, snoozing, and archiving a thread each show
51-
a notification with **Undo** for five seconds (it stays while the pointer is over it). Undo restores the thread's previous
51+
a notification with **Undo** for five seconds. Undo restores the thread's previous
5252
state, including its pinned position, and reopens an archived thread you were
5353
viewing. Discarding an unsent draft from the sidebar works the same way: Undo brings
5454
back its text and attachments. `mod+z` triggers the most recent Undo when the composer has no text or edits to undo and no native text field is focused; see

0 commit comments

Comments
 (0)