Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/web/src/lib/core/comments/MinimizedThreads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ export function MinimizedThread(props: {
document's scroll and clipping like the badge it opens from. */}
<Popover
open={expanded()}
onOpenChange={setExpanded}
onOpenChange={(open) => {
setExpanded(open);
// Discard a dismissed draft in the same tick; waiting for the
// editor's selection change paints its badge and highlight a frame.
// A thread activated by the same press keeps its selection.
if (!open && props.comment.isNew && props.isActive)
setActiveThread(null);
}}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
anchorRef={badge}
placement="left-start"
gutter={4}
Expand Down
41 changes: 41 additions & 0 deletions apps/web/src/lib/core/comments/Thread.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,47 @@ describe('anchored comment links', () => {
);
});

it.each([
[true, 'discards a draft as soon as a press outside dismisses it'],
[false, 'keeps a thread the dismissing press activated'],
])('%#: %s', async (isActive) => {
const setActiveThread = vi.fn();
const view = render(() => (
<CommentsContext.Provider
value={{
documentId: 'document',
documentType: 'md',
canComment: () => true,
isDocumentOwner: () => true,
highlightedCommentId: () => null,
setActiveThread,
setThreadHeight: () => {},
getCommentById: () => undefined,
ownedComment: () => false,
inComment: true,
commentOperations: noopCommentOperations,
messageOperations: { createComment: async () => null },
}}
>
<MinimizedThread
comment={{ ...comment, isNew: true }}
layout={{ calculatedYPos: 0 }}
isActive={isActive}
/>
</CommentsContext.Provider>
));
await new Promise((resolve) => setTimeout(resolve));
fireEvent.pointerDown(document.body);
await waitFor(() =>
expect(
view.container.ownerDocument
.querySelector('[data-comment-thread]')!
.parentElement!.hasAttribute('data-expanded')
).toBe(false)
);
expect(setActiveThread.mock.calls).toEqual(isActive ? [[null]] : []);
});

it.each(['md', 'task', 'snippet', 'skill', 'pdf'] as const)(
'copies legacy %s root and reply links without a block provider',
async (documentType) => {
Expand Down
Loading