-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Clear prompt input value when onDidEndShellExecution #286791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,12 @@ export interface IPromptInputModel extends IPromptInputModelState { | |||||||
| getCombinedString(emptyStringWhenEmpty?: boolean): string; | ||||||||
|
|
||||||||
| setShellType(shellType?: TerminalShellType): void; | ||||||||
|
|
||||||||
| /** | ||||||||
| * Clears the prompt input value. This should be called when the command has finished | ||||||||
| * and the value is no longer relevant as editable prompt input. | ||||||||
| */ | ||||||||
| clearValue(): void; | ||||||||
| } | ||||||||
|
|
||||||||
| export interface IPromptInputModelState { | ||||||||
|
|
@@ -239,8 +245,10 @@ export class PromptInputModel extends Disposable implements IPromptInputModel { | |||||||
|
|
||||||||
| private _handleCommandExecuted() { | ||||||||
| if (this._state === PromptInputState.Execute) { | ||||||||
| this._logService.trace('PromptInputModel#_handleCommandExecuted: already in Execute state'); | ||||||||
| return; | ||||||||
| } | ||||||||
| this._logService.trace('PromptInputModel#_handleCommandExecuted: Inside _handleCommandExecuted but not PromptInputState.Execute yet'); | ||||||||
|
|
||||||||
| this._cursorIndex = -1; | ||||||||
|
|
||||||||
|
|
@@ -261,6 +269,14 @@ export class PromptInputModel extends Disposable implements IPromptInputModel { | |||||||
| this._onDidChangeInput.fire(event); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Clears the prompt input value. This should be called when the command has finished | ||||||||
| * and the value is no longer relevant as editable prompt input. | ||||||||
| */ | ||||||||
| clearValue(): void { | ||||||||
| this._value = ''; | ||||||||
|
||||||||
| this._value = ''; | |
| this._value = ''; | |
| this._onDidChangeInput.fire(this._createStateObject()); |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new clearValue method lacks test coverage. There is a comprehensive test file at src/vs/platform/terminal/test/common/capabilities/commandDetection/promptInputModel.test.ts with tests for other prompt input model behaviors. Consider adding tests that verify clearValue properly clears the state and handles edge cases like calling clearValue multiple times or calling it in different states (Input, Execute, Unknown).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clearValue method only clears the _value field but leaves other state fields like _cursorIndex, _ghostTextIndex, _state, _commandStartMarker, and _commandStartX unchanged. This creates an inconsistent state where the value is empty but other tracking fields still reference the old command. Consider also resetting these fields or at minimum _cursorIndex and _ghostTextIndex to maintain state consistency. Looking at _handleCommandStart (line 219-220), it clears both _value and _cursorIndex together.