fix(desktop): add native clipboard image paste and fix text paste (#12682)

This commit is contained in:
Abdul Rahman ArM
2026-02-08 16:54:09 +05:30
committed by GitHub
parent d1ebe0767c
commit d5036cf01f
7 changed files with 47 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ import { Persist, persisted } from "@/utils/persist"
import { SessionContextUsage } from "@/components/session-context-usage"
import { usePermission } from "@/context/permission"
import { useLanguage } from "@/context/language"
import { usePlatform } from "@/context/platform"
import { createTextFragment, getCursorPosition, setCursorPosition, setRangeEdge } from "./prompt-input/editor-dom"
import { createPromptAttachments, ACCEPTED_FILE_TYPES } from "./prompt-input/attachments"
import { navigatePromptHistory, prependHistoryEntry, promptLength } from "./prompt-input/history"
@@ -97,6 +98,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
const command = useCommand()
const permission = usePermission()
const language = useLanguage()
const platform = usePlatform()
let editorRef!: HTMLDivElement
let fileInputRef!: HTMLInputElement
let scrollRef!: HTMLDivElement
@@ -766,6 +768,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
setCursorPosition(editorRef, promptLength(prompt.current()))
},
addPart,
readClipboardImage: platform.readClipboardImage,
})
const { abort, handleSubmit } = createPromptSubmit({

View File

@@ -14,6 +14,7 @@ type PromptAttachmentsInput = {
setDraggingType: (type: "image" | "@mention" | null) => void
focusEditor: () => void
addPart: (part: ContentPart) => void
readClipboardImage?: () => Promise<File | null>
}
export function createPromptAttachments(input: PromptAttachmentsInput) {
@@ -76,6 +77,16 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
}
const plainText = clipboardData.getData("text/plain") ?? ""
// Desktop: Browser clipboard has no images and no text, try platform's native clipboard for images
if (input.readClipboardImage && !plainText) {
const file = await input.readClipboardImage()
if (file) {
await addImageAttachment(file)
return
}
}
if (!plainText) return
input.addPart({ type: "text", content: plainText, start: 0, end: 0 })
}