@@ -20,9 +20,9 @@ const enum PromptInputState {
20
20
}
21
21
22
22
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 > ;
26
26
27
27
readonly value : string ;
28
28
readonly cursorIndex : number ;
@@ -35,6 +35,12 @@ export interface IPromptInputModel {
35
35
getCombinedString ( ) : string ;
36
36
}
37
37
38
+ export interface IPromptInputModelState {
39
+ readonly value : string ;
40
+ readonly cursorIndex : number ;
41
+ readonly ghostTextIndex : number ;
42
+ }
43
+
38
44
export class PromptInputModel extends Disposable implements IPromptInputModel {
39
45
private _state : PromptInputState = PromptInputState . Unknown ;
40
46
@@ -51,11 +57,11 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
51
57
private _ghostTextIndex : number = - 1 ;
52
58
get ghostTextIndex ( ) { return this . _ghostTextIndex ; }
53
59
54
- private readonly _onDidStartInput = this . _register ( new Emitter < void > ( ) ) ;
60
+ private readonly _onDidStartInput = this . _register ( new Emitter < IPromptInputModelState > ( ) ) ;
55
61
readonly onDidStartInput = this . _onDidStartInput . event ;
56
- private readonly _onDidChangeInput = this . _register ( new Emitter < void > ( ) ) ;
62
+ private readonly _onDidChangeInput = this . _register ( new Emitter < IPromptInputModelState > ( ) ) ;
57
63
readonly onDidChangeInput = this . _onDidChangeInput . event ;
58
- private readonly _onDidFinishInput = this . _register ( new Emitter < void > ( ) ) ;
64
+ private readonly _onDidFinishInput = this . _register ( new Emitter < IPromptInputModelState > ( ) ) ;
59
65
readonly onDidFinishInput = this . _onDidFinishInput . event ;
60
66
61
67
constructor (
@@ -105,7 +111,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
105
111
this . _commandStartX = this . _xterm . buffer . active . cursorX ;
106
112
this . _value = '' ;
107
113
this . _cursorIndex = 0 ;
108
- this . _onDidStartInput . fire ( ) ;
114
+ this . _onDidStartInput . fire ( this . _createStateObject ( ) ) ;
109
115
}
110
116
111
117
private _handleCommandExecuted ( ) {
@@ -115,7 +121,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
115
121
116
122
this . _state = PromptInputState . Execute ;
117
123
this . _cursorIndex = - 1 ;
118
- this . _onDidFinishInput . fire ( ) ;
124
+ this . _onDidFinishInput . fire ( this . _createStateObject ( ) ) ;
119
125
}
120
126
121
127
private _handleInput ( data : string ) {
@@ -197,7 +203,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
197
203
this . _value = value ;
198
204
this . _cursorIndex = cursorIndex ;
199
205
this . _ghostTextIndex = ghostTextIndex ;
200
- this . _onDidChangeInput . fire ( ) ;
206
+ this . _onDidChangeInput . fire ( this . _createStateObject ( ) ) ;
201
207
}
202
208
}
203
209
@@ -272,4 +278,12 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
272
278
private _isCellStyledLikeGhostText ( cell : IBufferCell ) : boolean {
273
279
return ! ! ( cell . isItalic ( ) || cell . isDim ( ) ) ;
274
280
}
281
+
282
+ private _createStateObject ( ) : IPromptInputModelState {
283
+ return Object . freeze ( {
284
+ value : this . _value ,
285
+ cursorIndex : this . _cursorIndex ,
286
+ ghostTextIndex : this . _ghostTextIndex
287
+ } ) ;
288
+ }
275
289
}
0 commit comments