@@ -799,6 +799,7 @@ export function Prompt(props: PromptProps) {
799799 virtual : true ,
800800 styleId,
801801 typeId : promptPartTypeId ,
802+ data : ref . type === "pasted" ? { pasted : prompt . pasted [ ref . index ] . text , label : mention . text } : undefined ,
802803 } )
803804 setStore ( "extmarkToPart" , ( map : Map < number , PromptPartRef > ) => {
804805 const newMap = new Map ( map )
@@ -821,6 +822,19 @@ export function Prompt(props: PromptProps) {
821822 const pasted : PromptInfo [ "pasted" ] = [ ]
822823
823824 for ( const extmark of allExtmarks ) {
825+ // Undo restores the extmark after its entry in the live prompt has been removed.
826+ if ( typeof extmark . data ?. pasted === "string" && typeof extmark . data ?. label === "string" ) {
827+ if ( input . getTextRange ( extmark . start , extmark . end ) !== extmark . data . label ) {
828+ input . extmarks . delete ( extmark . id )
829+ continue
830+ }
831+ newMap . set ( extmark . id , { type : "pasted" , index : pasted . length } )
832+ pasted . push ( {
833+ text : extmark . data . pasted ,
834+ source : { start : extmark . start , end : extmark . end , text : extmark . data . label } ,
835+ } )
836+ continue
837+ }
824838 const ref = draft . extmarkToPart . get ( extmark . id )
825839 if ( ! ref ) continue
826840 if ( ref . type === "file" ) {
@@ -850,15 +864,7 @@ export function Prompt(props: PromptProps) {
850864 const index = skills . length
851865 skills . push ( part )
852866 newMap . set ( extmark . id , { type : "skill" , index } )
853- continue
854867 }
855- const part = draft . prompt . pasted [ ref . index ]
856- if ( ! part ) continue
857- part . source . start = extmark . start
858- part . source . end = extmark . end
859- const index = pasted . length
860- pasted . push ( part )
861- newMap . set ( extmark . id , { type : "pasted" , index } )
862868 }
863869
864870 const nextFiles = preserveMentionlessPromptAttachments ( draft . prompt . files , files )
@@ -1405,6 +1411,7 @@ export function Prompt(props: PromptProps) {
14051411 virtual : true ,
14061412 styleId : pasteStyleId ,
14071413 typeId : promptPartTypeId ,
1414+ data : { pasted : text , label : virtualText } ,
14081415 } )
14091416
14101417 setStore (
@@ -1426,7 +1433,6 @@ export function Prompt(props: PromptProps) {
14261433 const part = store . prompt . pasted [ ref . index ]
14271434 if ( ! part ) return false
14281435
1429- input . extmarks . delete ( extmarkId )
14301436 input . setSelection ( extmark . start , extmark . end )
14311437 input . insertText ( part . text )
14321438 return true
0 commit comments