@@ -56,11 +56,11 @@ import {
5656 handle_proceed_with_commit ,
5757 handle_get_collapsed_states ,
5858 handle_manage_configurations ,
59- handle_save_component_collapsed_state
59+ handle_save_component_collapsed_state ,
60+ handle_undo
6061} from './message-handlers'
6162import {
6263 API_EDIT_FORMAT_STATE_KEY ,
63- LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY ,
6464 API_MODE_STATE_KEY ,
6565 CHAT_EDIT_FORMAT_STATE_KEY ,
6666 INSTRUCTIONS_ASK_STATE_KEY ,
@@ -72,7 +72,6 @@ import {
7272 get_last_selected_group_state_key ,
7373 get_last_selected_preset_key ,
7474 LAST_APPLIED_CHANGES_STATE_KEY ,
75- LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY ,
7675 LAST_SELECTED_CODE_COMPLETION_CONFIG_ID_STATE_KEY ,
7776 LAST_SELECTED_EDIT_CONTEXT_CONFIG_ID_STATE_KEY ,
7877 get_presets_collapsed_state_key ,
@@ -91,7 +90,6 @@ import { response_preview_promise_resolve } from '@/commands/apply-chat-response
9190import { Logger } from '@shared/utils/logger'
9291import { CancelTokenSource } from 'axios'
9392import { update_last_used_preset_or_group } from './message-handlers/update-last-used-preset-or-group'
94- import { undo_files } from '@/commands/apply-chat-response-command/utils/file-operations'
9593import { dictionary } from '@shared/constants/dictionary'
9694
9795export class PanelProvider implements vscode . WebviewViewProvider {
@@ -449,7 +447,7 @@ export class PanelProvider implements vscode.WebviewViewProvider {
449447 create_on_index : message . create_on_index
450448 } )
451449 } else if ( message . command == 'UNDO' ) {
452- await this . _handle_undo ( )
450+ await handle_undo ( this )
453451 } else if ( message . command == 'APPLY_RESPONSE_FROM_HISTORY' ) {
454452 await vscode . commands . executeCommand (
455453 'codeWebChat.applyChatResponse' ,
@@ -851,74 +849,6 @@ export class PanelProvider implements vscode.WebviewViewProvider {
851849 return ! ! original_states && original_states . length > 0
852850 }
853851
854- private async _handle_undo ( ) : Promise < void > {
855- const context = this . context
856- const original_states = context . workspaceState . get < OriginalFileState [ ] > (
857- LAST_APPLIED_CHANGES_STATE_KEY
858- )
859- const editor_state = context . workspaceState . get <
860- | {
861- file_path : string
862- position : { line : number ; character : number }
863- }
864- | undefined
865- > ( LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY )
866-
867- if ( ! original_states || original_states . length == 0 ) {
868- vscode . window . showInformationMessage (
869- dictionary . information_message . NO_RECENT_CHANGES_TO_UNDO
870- )
871- return
872- }
873-
874- try {
875- const success = await undo_files ( { original_states } )
876-
877- if ( ! success ) {
878- return
879- }
880-
881- if ( editor_state ) {
882- try {
883- const uri = vscode . Uri . file ( editor_state . file_path )
884- const document = await vscode . workspace . openTextDocument ( uri )
885- const editor = await vscode . window . showTextDocument ( document , {
886- preview : false
887- } )
888- const position = new vscode . Position (
889- editor_state . position . line ,
890- editor_state . position . character
891- )
892- editor . selection = new vscode . Selection ( position , position )
893- editor . revealRange (
894- new vscode . Range ( position , position ) ,
895- vscode . TextEditorRevealType . InCenter
896- )
897- } catch ( error ) {
898- console . error ( 'Error restoring editor state:' , error )
899- }
900- }
901-
902- context . workspaceState . update ( LAST_APPLIED_CHANGES_STATE_KEY , null )
903- context . workspaceState . update (
904- LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY ,
905- null
906- )
907- context . workspaceState . update (
908- LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY ,
909- null
910- )
911- this . set_undo_button_state ( false )
912- } catch ( error : any ) {
913- console . error ( 'Error during undo:' , error )
914- vscode . window . showErrorMessage (
915- dictionary . error_message . FAILED_TO_UNDO_CHANGES (
916- error . message || 'Unknown error'
917- )
918- )
919- }
920- }
921-
922852 private _get_html_for_webview ( webview : vscode . Webview ) {
923853 const resources_uri = webview . asWebviewUri (
924854 vscode . Uri . joinPath ( this . extension_uri , 'resources' )
0 commit comments