Skip to content

Commit 4f619ff

Browse files
committed
Fire event with object
1 parent 6ceb862 commit 4f619ff

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

src/vs/platform/terminal/common/capabilities/commandDetection/promptInputModel.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const enum PromptInputState {
2020
}
2121

2222
export interface IPromptInputModel {
23-
readonly onDidStartInput: Event<void>;
24-
readonly onDidChangeInput: Event<void>;
25-
readonly onDidFinishInput: Event<void>;
23+
readonly onDidStartInput: Event<IPromptInputModelState>;
24+
readonly onDidChangeInput: Event<IPromptInputModelState>;
25+
readonly onDidFinishInput: Event<IPromptInputModelState>;
2626

2727
readonly value: string;
2828
readonly cursorIndex: number;
@@ -35,6 +35,12 @@ export interface IPromptInputModel {
3535
getCombinedString(): string;
3636
}
3737

38+
export interface IPromptInputModelState {
39+
readonly value: string;
40+
readonly cursorIndex: number;
41+
readonly ghostTextIndex: number;
42+
}
43+
3844
export class PromptInputModel extends Disposable implements IPromptInputModel {
3945
private _state: PromptInputState = PromptInputState.Unknown;
4046

@@ -51,11 +57,11 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
5157
private _ghostTextIndex: number = -1;
5258
get ghostTextIndex() { return this._ghostTextIndex; }
5359

54-
private readonly _onDidStartInput = this._register(new Emitter<void>());
60+
private readonly _onDidStartInput = this._register(new Emitter<IPromptInputModelState>());
5561
readonly onDidStartInput = this._onDidStartInput.event;
56-
private readonly _onDidChangeInput = this._register(new Emitter<void>());
62+
private readonly _onDidChangeInput = this._register(new Emitter<IPromptInputModelState>());
5763
readonly onDidChangeInput = this._onDidChangeInput.event;
58-
private readonly _onDidFinishInput = this._register(new Emitter<void>());
64+
private readonly _onDidFinishInput = this._register(new Emitter<IPromptInputModelState>());
5965
readonly onDidFinishInput = this._onDidFinishInput.event;
6066

6167
constructor(
@@ -105,7 +111,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
105111
this._commandStartX = this._xterm.buffer.active.cursorX;
106112
this._value = '';
107113
this._cursorIndex = 0;
108-
this._onDidStartInput.fire();
114+
this._onDidStartInput.fire(this._createStateObject());
109115
}
110116

111117
private _handleCommandExecuted() {
@@ -115,7 +121,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
115121

116122
this._state = PromptInputState.Execute;
117123
this._cursorIndex = -1;
118-
this._onDidFinishInput.fire();
124+
this._onDidFinishInput.fire(this._createStateObject());
119125
}
120126

121127
private _handleInput(data: string) {
@@ -197,7 +203,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
197203
this._value = value;
198204
this._cursorIndex = cursorIndex;
199205
this._ghostTextIndex = ghostTextIndex;
200-
this._onDidChangeInput.fire();
206+
this._onDidChangeInput.fire(this._createStateObject());
201207
}
202208
}
203209

@@ -272,4 +278,12 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
272278
private _isCellStyledLikeGhostText(cell: IBufferCell): boolean {
273279
return !!(cell.isItalic() || cell.isDim());
274280
}
281+
282+
private _createStateObject(): IPromptInputModelState {
283+
return Object.freeze({
284+
value: this._value,
285+
cursorIndex: this._cursorIndex,
286+
ghostTextIndex: this._ghostTextIndex
287+
});
288+
}
275289
}

src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { sanitizeCwd } from 'vs/platform/terminal/common/terminalEnvironment';
4040
/**
4141
* The identifier for the first numeric parameter (`Ps`) for OSC commands used by shell integration.
4242
*/
43-
const enum ShellIntegrationOscPs {
43+
export const enum ShellIntegrationOscPs {
4444
/**
4545
* Sequences pioneered by FinalTerm.
4646
*/

src/vs/platform/terminal/test/common/capabilities/commandDetection/promptInputModel.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
77
import { NullLogService } from 'vs/platform/log/common/log';
8-
import { PromptInputModel } from 'vs/platform/terminal/common/capabilities/commandDetection/promptInputModel';
8+
import { PromptInputModel, type IPromptInputModelState } from 'vs/platform/terminal/common/capabilities/commandDetection/promptInputModel';
99
import { Emitter } from 'vs/base/common/event';
1010
import type { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities';
1111

@@ -79,18 +79,8 @@ suite('PromptInputModel', () => {
7979
});
8080

8181
test('should not fire events when nothing changes', async () => {
82-
const events: {
83-
value: string;
84-
cursorIndex: number;
85-
ghostTextIndex: number;
86-
}[] = [];
87-
store.add(promptInputModel.onDidChangeInput(() => {
88-
events.push({
89-
value: promptInputModel.value,
90-
cursorIndex: promptInputModel.cursorIndex,
91-
ghostTextIndex: promptInputModel.ghostTextIndex
92-
});
93-
}));
82+
const events: IPromptInputModelState[] = [];
83+
store.add(promptInputModel.onDidChangeInput(e => events.push(e)));
9484

9585
await writePromise('$ ');
9686
fireCommandStart();

0 commit comments

Comments
 (0)