diff --git a/src/extension.ts b/src/extension.ts index 8fa37fb..336e9cc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -215,6 +215,10 @@ class ClaudeChatProvider { // Load saved model preference this._selectedModel = this._context.workspaceState.get('claude.selectedModel', 'default'); + // Load persisted input draft so it survives panel disposal / VS Code + // restarts, restored to the webview once ready + this._draftMessage = this._context.workspaceState.get('claudeCodeChat.inputDraft', ''); + // Load cached subscription type (will be refreshed on first message) this._subscriptionType = this._context.globalState.get('claude.subscriptionType'); @@ -895,6 +899,7 @@ class ClaudeChatProvider { // Clear draft message since we're sending it this._draftMessage = ''; + this._context.workspaceState.update('claudeCodeChat.inputDraft', undefined); // Show original user input in chat and save to conversation (without mode prefixes) this._sendAndSaveMessage({ @@ -3428,6 +3433,12 @@ class ClaudeChatProvider { private _saveInputText(text: string): void { this._draftMessage = text || ''; + // Persist so the draft survives panel disposal and VS Code restarts + if (this._draftMessage.trim()) { + this._context.workspaceState.update('claudeCodeChat.inputDraft', this._draftMessage); + } else { + this._context.workspaceState.update('claudeCodeChat.inputDraft', undefined); + } } private async _updateSettings(settings: { [key: string]: any }): Promise { diff --git a/src/script.ts b/src/script.ts index 4c949e2..708413c 100644 --- a/src/script.ts +++ b/src/script.ts @@ -949,6 +949,14 @@ const getScript = (isTelemetryEnabled: boolean, opencreditsApiUrl: string = 'htt messageInput.value = ''; attachedImages = []; renderImagePreviews(); + + // Clear the persisted draft immediately so no stale text survives + // a restart shortly after sending + clearTimeout(saveInputTimeout); + vscode.postMessage({ + type: 'saveInputText', + text: '' + }); } } @@ -3553,7 +3561,10 @@ const getScript = (isTelemetryEnabled: boolean, opencreditsApiUrl: string = 'htt case 'restoreInputText': const inputField = document.getElementById('messageInput'); - if (inputField && message.data) { + // retainContextWhenHidden already keeps in-progress typing across tab + // switches, so this restore is only the fallback for a fresh panel / + // VS Code restart — don't clobber text the user already has + if (inputField && message.data && !inputField.value.trim()) { inputField.value = message.data; // Auto-resize the textarea inputField.style.height = 'auto';