@@ -148,6 +148,10 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
148148 } , [ ] ) ;
149149 const inputRef = useRef < HTMLTextAreaElement > ( null ) ;
150150 const modelSelectorRef = useRef < ModelSelectorRef > ( null ) ;
151+ const preEditStateRef = useRef < { input : string ; images : ImageAttachment [ ] } > ( {
152+ input : "" ,
153+ images : [ ] ,
154+ } ) ;
151155 const [ mode , setMode ] = useMode ( ) ;
152156 const { recentModels, addModel, defaultModel, setDefaultModel } = useModelLRU ( ) ;
153157 const commandListId = useId ( ) ;
@@ -346,10 +350,12 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
346350 } ;
347351 } , [ focusMessageInput ] ) ;
348352
349- // When entering editing mode, populate input with message content
353+ // When entering editing mode, save current input/images and populate with message content
350354 useEffect ( ( ) => {
351355 if ( editingMessage ) {
356+ preEditStateRef . current = { input, images : imageAttachments } ;
352357 setInput ( editingMessage . content ) ;
358+ setImageAttachments ( [ ] ) ; // Clear images when editing (edited message may have different images)
353359 // Auto-resize textarea and focus
354360 setTimeout ( ( ) => {
355361 if ( inputRef . current ) {
@@ -360,6 +366,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
360366 }
361367 } , 0 ) ;
362368 }
369+ // eslint-disable-next-line react-hooks/exhaustive-deps -- only run when editingMessage changes, not input/images
363370 } , [ editingMessage , setInput ] ) ;
364371
365372 // Watch input for slash commands
@@ -829,6 +836,8 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
829836 // Handler for Escape in vim normal mode - cancels edit if editing
830837 const handleEscapeInNormalMode = ( ) => {
831838 if ( variant === "workspace" && editingMessage && props . onCancelEdit ) {
839+ setInput ( preEditStateRef . current . input ) ;
840+ setImageAttachments ( preEditStateRef . current . images ) ;
832841 props . onCancelEdit ( ) ;
833842 inputRef . current ?. blur ( ) ;
834843 }
@@ -884,6 +893,8 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
884893 if ( matchesKeybind ( e , KEYBINDS . CANCEL_EDIT ) ) {
885894 if ( variant === "workspace" && editingMessage && props . onCancelEdit && ! vimEnabled ) {
886895 e . preventDefault ( ) ;
896+ setInput ( preEditStateRef . current . input ) ;
897+ setImageAttachments ( preEditStateRef . current . images ) ;
887898 props . onCancelEdit ( ) ;
888899 const isFocused = document . activeElement === inputRef . current ;
889900 if ( isFocused ) {
0 commit comments