@@ -72,6 +72,7 @@ let currentIndexHistory = 0;
7272let currentActionInProgress = null ;
7373let typingInterval = null ;
7474let currentGenerationIndex = 0 ;
75+ let contentBeforeGeneration = "" ;
7576
7677const textarea = document . getElementById ( 'ai-textarea' ) ;
7778const menu = document . getElementById ( 'ai-menu' ) ;
@@ -95,7 +96,7 @@ function updateComponentState(versionIndex = null) {
9596 textarea . value = versionHistory [ versionIndex ] . value ;
9697 }
9798
98- textarea . currentVersion = currentIndexHistory ;
99+ textarea . currentVersion = currentIndexHistory + 1 ;
99100 textarea . totalVersions = versionHistory . length ;
100101
101102 if ( versionHistory [ currentIndexHistory ] ) {
@@ -242,6 +243,7 @@ async function executeAction(action) {
242243 const textKey = menuItem . dataset . textKey || 'en' ;
243244
244245 saveCurrentVersion ( ) ;
246+ contentBeforeGeneration = textarea . value ;
245247 currentActionInProgress = action ;
246248 currentGenerationIndex += 1 ;
247249 const generationIdForThisRun = currentGenerationIndex ;
@@ -267,22 +269,26 @@ function stopGeneration() {
267269
268270 stopTypingAnimation ( ) ;
269271 currentGenerationIndex += 1 ;
270- const action = currentActionInProgress || 'generate' ;
271- const menuItem = findMenuItemByAction ( action ) ;
272- const completedLabel = ( menuItem && menuItem . dataset . completedLabel ) ? menuItem . dataset . completedLabel : 'Action completed' ;
273-
274- versionHistory . push ( {
275- value : textarea . value ,
276- action,
277- endAction : completedLabel + " (stopped)" ,
278- timestamp : new Date ( ) . toISOString ( )
279- } ) ;
272+
273+ const stoppedValue = textarea . value ;
274+ if ( stoppedValue . trim ( ) ) {
275+ const action = currentActionInProgress || 'generate' ;
276+ const menuItem = findMenuItemByAction ( action ) ;
277+ const completedLabel = ( menuItem && menuItem . dataset . completedLabel ) ? menuItem . dataset . completedLabel : 'Action completed' ;
278+
279+ versionHistory . push ( {
280+ value : stoppedValue ,
281+ action,
282+ endAction : completedLabel + " (stopped)" ,
283+ timestamp : new Date ( ) . toISOString ( )
284+ } ) ;
285+
286+ currentIndexHistory = versionHistory . length - 1 ;
287+ buildMenuFromConfig ( ) ;
288+ updateComponentState ( ) ;
289+ }
280290
281- currentIndexHistory = versionHistory . length - 1 ;
282291 currentActionInProgress = null ;
283-
284- buildMenuFromConfig ( ) ;
285- updateComponentState ( ) ;
286292 textarea . loading = false ;
287293}
288294
0 commit comments