Skip to content

Commit 2e5f8f5

Browse files
committed
fix(chat): don't swallow a paste whose selection chip is already attached
Cursor Bugbot: the selection-paste path called preventDefault before prepareContextForInsert, so when that returned null (the same selection is already a chip) the handler returned having claimed the event — no chip inserted and no text/plain pasted either. Cmd+V did nothing. preventDefault now waits until there is a chip to insert; a duplicate falls through to the plain-text paste below, which is the reasonable reading of the gesture.
1 parent b20cfcd commit 2e5f8f5

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,14 +929,18 @@ export function usePromptEditor({
929929
// custom clipboard type — paste it as a reference chip instead of plain text.
930930
// Registers via `addContext` (not the notified path) so paste never opens a
931931
// side panel, matching the portable-chip-link paste below.
932+
//
933+
// `preventDefault` waits until there is a chip to insert: when the selection
934+
// is already attached there is nothing to add, and claiming the event anyway
935+
// would swallow the keystroke entirely — no chip and no text. Falling through
936+
// pastes the selection's plain text, which is what the user asked for.
932937
const selectionContext = readSelectionContextFromClipboard(e.clipboardData)
933-
if (selectionContext) {
938+
const preparedSelection = selectionContext
939+
? prepareContextForInsert(selectionContext, contextManagementRef.current.selectedContexts)
940+
: null
941+
if (preparedSelection) {
934942
e.preventDefault()
935-
const prepared = prepareContextForInsert(
936-
selectionContext,
937-
contextManagementRef.current.selectedContexts
938-
)
939-
if (!prepared) return
943+
const prepared = preparedSelection
940944
const selStart = textarea.selectionStart ?? valueRef.current.length
941945
const selEnd = textarea.selectionEnd ?? selStart
942946
const needsSpaceBefore = selStart > 0 && !/\s/.test(valueRef.current.charAt(selStart - 1))

0 commit comments

Comments
 (0)