From 1d97c035ef102802be2c3e02829747cdb1d4f486 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sat, 1 Aug 2026 01:49:32 -0500 Subject: [PATCH] =?UTF-8?q?fix(desktop):=20drag-select=20and=20=E2=8C=98C?= =?UTF-8?q?=20work=20on=20user=20bubbles=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User bubbles are buttons, so the global user-select:none rule killed text selection. Right-click-to-react and click-to-edit also ate a live highlight. Prefer selection when one exists. --- .../thread/user-message-selection.test.ts | 28 +++++++++++++ .../assistant-ui/thread/user-message.tsx | 40 +++++++++++++++++-- apps/desktop/src/styles.css | 9 +++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 apps/desktop/src/components/assistant-ui/thread/user-message-selection.test.ts diff --git a/apps/desktop/src/components/assistant-ui/thread/user-message-selection.test.ts b/apps/desktop/src/components/assistant-ui/thread/user-message-selection.test.ts new file mode 100644 index 0000000000..0b766c062a --- /dev/null +++ b/apps/desktop/src/components/assistant-ui/thread/user-message-selection.test.ts @@ -0,0 +1,28 @@ +import { afterEach, describe, expect, it } from 'vitest' + +import { hasTextSelection } from './user-message' + +afterEach(() => { + window.getSelection()?.removeAllRanges() + document.body.replaceChildren() +}) + +describe('hasTextSelection', () => { + it('is false with nothing highlighted', () => { + expect(hasTextSelection()).toBe(false) + }) + + it('is true once the user has a live range', () => { + const node = document.createElement('span') + node.textContent = 'copy me' + document.body.appendChild(node) + + const range = document.createRange() + range.selectNodeContents(node) + const selection = window.getSelection()! + selection.removeAllRanges() + selection.addRange(range) + + expect(hasTextSelection()).toBe(true) + }) +}) diff --git a/apps/desktop/src/components/assistant-ui/thread/user-message.tsx b/apps/desktop/src/components/assistant-ui/thread/user-message.tsx index 16c6963e24..2ea43309df 100644 --- a/apps/desktop/src/components/assistant-ui/thread/user-message.tsx +++ b/apps/desktop/src/components/assistant-ui/thread/user-message.tsx @@ -16,6 +16,13 @@ import { cn } from '@/lib/utils' import { notifyThreadEditOpen } from '@/store/thread-scroll' import { isWatchWindow } from '@/store/windows' +/** True when the user has a live text highlight (drag-select / triple-click). */ +export function hasTextSelection(): boolean { + const selection = window.getSelection() + + return Boolean(selection && !selection.isCollapsed && selection.toString().length > 0) +} + export function StickyHumanMessageContainer({ attachments, children, @@ -279,10 +286,16 @@ export const UserMessage: FC<{
{ + if (hasTextSelection()) { + return + } + event.preventDefault() setPickerOpen(true) } @@ -295,7 +308,9 @@ export const UserMessage: FC<{ aria-expanded={bodyClamped ? expanded : undefined} className={cn(bubbleClassName, !bodyClamped && 'cursor-default')} onClick={() => { - if (!bodyClamped) { + // Drag-select ends on mouseup→click; don't collapse the + // clamp just because the highlight finished. + if (hasTextSelection() || !bodyClamped) { return } @@ -310,12 +325,29 @@ export const UserMessage: FC<{ ) : ( // Always editable — clicking opens the edit composer even while a // turn streams; sending the edit reverts (interrupt + rewind). + // A live text highlight wins: finishing a drag-select must not + // open the editor and throw the selection away.