feat(tui): expand pasted text (#39920)
This commit is contained in:
parent
b498a5c6c4
commit
3bfce3fd2d
1 changed files with 29 additions and 1 deletions
|
|
@ -1168,6 +1168,19 @@ export function Prompt(props: PromptProps) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expandPastedText(extmarkId: number) {
|
||||||
|
const extmark = input.extmarks.get(extmarkId)
|
||||||
|
const ref = store.extmarkToPart.get(extmarkId)
|
||||||
|
if (!extmark || ref?.type !== "pasted") return false
|
||||||
|
const part = store.prompt.pasted[ref.index]
|
||||||
|
if (!part) return false
|
||||||
|
|
||||||
|
input.extmarks.delete(extmarkId)
|
||||||
|
input.setSelection(extmark.start, extmark.end)
|
||||||
|
input.insertText(part.text)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
async function pasteInputText(text: string) {
|
async function pasteInputText(text: string) {
|
||||||
const normalizedText = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
const normalizedText = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
||||||
const pastedContent = normalizedText.trim()
|
const pastedContent = normalizedText.trim()
|
||||||
|
|
@ -1191,6 +1204,15 @@ export function Prompt(props: PromptProps) {
|
||||||
|
|
||||||
const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
|
const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
|
||||||
if ((lineCount >= 3 || pastedContent.length > 150) && config.prompt?.paste !== "full") {
|
if ((lineCount >= 3 || pastedContent.length > 150) && config.prompt?.paste !== "full") {
|
||||||
|
const extmark = input.extmarks.getAllForTypeId(promptPartTypeId).find((extmark) => {
|
||||||
|
const ref = store.extmarkToPart.get(extmark.id)
|
||||||
|
return (
|
||||||
|
(extmark.end === input.cursorOffset || extmark.end + 1 === input.cursorOffset) &&
|
||||||
|
ref?.type === "pasted" &&
|
||||||
|
store.prompt.pasted[ref.index]?.text === pastedContent
|
||||||
|
)
|
||||||
|
})
|
||||||
|
if (extmark && expandPastedText(extmark.id)) return
|
||||||
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
|
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1425,8 +1447,14 @@ export function Prompt(props: PromptProps) {
|
||||||
}, 0)
|
}, 0)
|
||||||
}}
|
}}
|
||||||
onMouseDown={(r: MouseEvent) => {
|
onMouseDown={(r: MouseEvent) => {
|
||||||
if (props.disabled) return
|
if (props.disabled || r.button !== 0) return
|
||||||
r.target?.focus()
|
r.target?.focus()
|
||||||
|
const extmark = input.extmarks
|
||||||
|
.getAtOffset(input.cursorOffset)
|
||||||
|
.find((item) => store.extmarkToPart.get(item.id)?.type === "pasted")
|
||||||
|
if (!extmark || !expandPastedText(extmark.id)) return
|
||||||
|
r.preventDefault()
|
||||||
|
r.stopPropagation()
|
||||||
}}
|
}}
|
||||||
focusedBackgroundColor="transparent"
|
focusedBackgroundColor="transparent"
|
||||||
cursorColor={props.disabled ? theme.background.surface.offset : theme.text.default}
|
cursorColor={props.disabled ? theme.background.surface.offset : theme.text.default}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue