fix: ensure that double pasting doesnt happen after tui perf commit was merged (#22880)
This commit is contained in:
@@ -1031,6 +1031,10 @@ export function Prompt(props: PromptProps) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Once we cross an async boundary below, the terminal may perform its
|
||||||
|
// default paste unless we suppress it first and handle insertion ourselves.
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
const filepath = iife(() => {
|
const filepath = iife(() => {
|
||||||
const raw = pastedContent.replace(/^['"]+|['"]+$/g, "")
|
const raw = pastedContent.replace(/^['"]+|['"]+$/g, "")
|
||||||
if (raw.startsWith("file://")) {
|
if (raw.startsWith("file://")) {
|
||||||
@@ -1048,7 +1052,6 @@ export function Prompt(props: PromptProps) {
|
|||||||
const filename = path.basename(filepath)
|
const filename = path.basename(filepath)
|
||||||
// Handle SVG as raw text content, not as base64 image
|
// Handle SVG as raw text content, not as base64 image
|
||||||
if (mime === "image/svg+xml") {
|
if (mime === "image/svg+xml") {
|
||||||
event.preventDefault()
|
|
||||||
const content = await Filesystem.readText(filepath).catch(() => {})
|
const content = await Filesystem.readText(filepath).catch(() => {})
|
||||||
if (content) {
|
if (content) {
|
||||||
pasteText(content, `[SVG: ${filename ?? "image"}]`)
|
pasteText(content, `[SVG: ${filename ?? "image"}]`)
|
||||||
@@ -1056,7 +1059,6 @@ export function Prompt(props: PromptProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mime.startsWith("image/") || mime === "application/pdf") {
|
if (mime.startsWith("image/") || mime === "application/pdf") {
|
||||||
event.preventDefault()
|
|
||||||
const content = await Filesystem.readArrayBuffer(filepath)
|
const content = await Filesystem.readArrayBuffer(filepath)
|
||||||
.then((buffer) => Buffer.from(buffer).toString("base64"))
|
.then((buffer) => Buffer.from(buffer).toString("base64"))
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
@@ -1078,11 +1080,12 @@ export function Prompt(props: PromptProps) {
|
|||||||
(lineCount >= 3 || pastedContent.length > 150) &&
|
(lineCount >= 3 || pastedContent.length > 150) &&
|
||||||
!sync.data.config.experimental?.disable_paste_summary
|
!sync.data.config.experimental?.disable_paste_summary
|
||||||
) {
|
) {
|
||||||
event.preventDefault()
|
|
||||||
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
|
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input.insertText(normalizedText)
|
||||||
|
|
||||||
// Force layout update and render for the pasted content
|
// Force layout update and render for the pasted content
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// setTimeout is a workaround and needs to be addressed properly
|
// setTimeout is a workaround and needs to be addressed properly
|
||||||
|
|||||||
Reference in New Issue
Block a user