@@ -25,10 +25,11 @@ import { useSync } from "@tui/context/sync"
2525import { useEvent } from "@tui/context/event"
2626import { editorSelectionKey , useEditorContext , type EditorSelection } from "@tui/context/editor"
2727import { MessageID , PartID } from "@/session/schema"
28+ import { promptOffsetWidth } from "@/cli/cmd/prompt-display"
2829import { createStore , produce , unwrap } from "solid-js/store"
2930import { usePromptHistory , type PromptInfo } from "./history"
3031import { computePromptTraits } from "./traits"
31- import { assign , expandPastedTextPlaceholders } from "./part"
32+ import { assign , expandPastedTextPlaceholders , expandTrackedPastedText } from "./part"
3233import { usePromptStash } from "./stash"
3334import { DialogStash } from "../dialog-stash"
3435import { type AutocompleteRef , Autocomplete } from "./autocomplete"
@@ -1109,23 +1110,15 @@ export function Prompt(props: PromptProps) {
11091110 }
11101111
11111112 const messageID = MessageID . ascending ( )
1112- let inputText = store . prompt . input
1113-
1114- // Expand pasted text inline before submitting
1115- const allExtmarks = input . extmarks . getAllForTypeId ( promptPartTypeId )
1116- const sortedExtmarks = allExtmarks . sort ( ( a : { start : number } , b : { start : number } ) => b . start - a . start )
1117-
1118- for ( const extmark of sortedExtmarks ) {
1119- const partIndex = store . extmarkToPartIndex . get ( extmark . id )
1120- if ( partIndex !== undefined ) {
1121- const part = store . prompt . parts [ partIndex ]
1122- if ( part ?. type === "text" && part . text ) {
1123- const before = inputText . slice ( 0 , extmark . start )
1124- const after = inputText . slice ( extmark . end )
1125- inputText = before + part . text + after
1126- }
1127- }
1128- }
1113+ const inputText = expandTrackedPastedText (
1114+ store . prompt . input ,
1115+ input . extmarks . getAllForTypeId ( promptPartTypeId ) . flatMap ( ( extmark ) => {
1116+ const partIndex = store . extmarkToPartIndex . get ( extmark . id )
1117+ const part = partIndex === undefined ? undefined : store . prompt . parts [ partIndex ]
1118+ if ( part ?. type !== "text" ) return [ ]
1119+ return [ { start : extmark . start , end : extmark . end , text : part . text } ]
1120+ } ) ,
1121+ )
11291122
11301123 // Filter out text parts (pasted content) since they're now expanded inline
11311124 const nonTextParts = store . prompt . parts . filter ( ( part ) => part . type !== "text" )
@@ -1242,9 +1235,9 @@ export function Prompt(props: PromptProps) {
12421235 const exit = useExit ( )
12431236
12441237 function pasteText ( text : string , virtualText : string ) {
1245- const currentOffset = input . visualCursor . offset
1238+ const currentOffset = input . cursorOffset
12461239 const extmarkStart = currentOffset
1247- const extmarkEnd = extmarkStart + virtualText . length
1240+ const extmarkEnd = extmarkStart + promptOffsetWidth ( virtualText )
12481241
12491242 input . insertText ( virtualText + " " )
12501243
@@ -1336,7 +1329,7 @@ export function Prompt(props: PromptProps) {
13361329 }
13371330
13381331 async function pasteAttachment ( file : { filename ?: string ; filepath ?: string ; content : string ; mime : string } ) {
1339- const currentOffset = input . visualCursor . offset
1332+ const currentOffset = input . cursorOffset
13401333 const extmarkStart = currentOffset
13411334 const pdf = file . mime === "application/pdf"
13421335 const count = store . prompt . parts . filter ( ( x ) => {
0 commit comments