@@ -39,7 +39,7 @@ import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_
39
39
import { chatAgentLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes' ;
40
40
import { IChatReplyFollowup } from 'vs/workbench/contrib/chat/common/chatService' ;
41
41
import { IChatResponseViewModel } from 'vs/workbench/contrib/chat/common/chatViewModel' ;
42
- import { IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService' ;
42
+ import { IChatHistoryEntry , IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService' ;
43
43
import { getSimpleCodeEditorWidgetOptions , getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions' ;
44
44
import { ChatSubmitEditorAction , ChatSubmitSecondaryAgentEditorAction } from 'vs/workbench/contrib/chat/browser/actions/chatActions' ;
45
45
import { IPosition } from 'vs/editor/common/core/position' ;
@@ -82,10 +82,10 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
82
82
return this . _inputEditor ;
83
83
}
84
84
85
- private history : HistoryNavigator < string > ;
86
- private historyStates : Map < string , any > = new Map ( ) ;
85
+ private history : HistoryNavigator < IChatHistoryEntry > ;
87
86
private historyNavigationBackwardsEnablement ! : IContextKey < boolean > ;
88
87
private historyNavigationForewardsEnablement ! : IContextKey < boolean > ;
88
+ private onHistoryEntry = false ;
89
89
private inputModel : ITextModel | undefined ;
90
90
private inputEditorHasText : IContextKey < boolean > ;
91
91
private chatCursorAtTop : IContextKey < boolean > ;
@@ -133,11 +133,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
133
133
setState ( providerId : string , inputValue : string | undefined ) : void {
134
134
this . providerId = providerId ;
135
135
const history = this . historyService . getHistory ( providerId ) ;
136
- this . historyStates = new Map ( history . map ( h => [ h . text , h . state ] ) ) ;
137
- const historyTexts : string [ ] = [ ] ;
138
- this . historyStates . forEach ( ( _ , str ) => historyTexts . push ( str ) ) ;
139
-
140
- this . history = new HistoryNavigator ( historyTexts , 50 ) ;
136
+ this . history = new HistoryNavigator ( history , 50 ) ;
141
137
142
138
if ( typeof inputValue === 'string' ) {
143
139
this . setValue ( inputValue ) ;
@@ -157,13 +153,15 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
157
153
}
158
154
159
155
private navigateHistory ( previous : boolean ) : void {
160
- const historyInput = ( previous ?
156
+ const historyEntry = ( previous ?
161
157
( this . history . previous ( ) ?? this . history . first ( ) ) : this . history . next ( ) )
162
- ?? '' ;
158
+ ?? { text : '' } ;
159
+
160
+ this . onHistoryEntry = previous || this . history . current ( ) !== null ;
163
161
164
- aria . status ( historyInput ) ;
165
- this . setValue ( historyInput ) ;
166
- this . _onDidLoadInputState . fire ( this . historyStates . get ( historyInput ) ) ;
162
+ aria . status ( historyEntry . text ) ;
163
+ this . setValue ( historyEntry . text ) ;
164
+ this . _onDidLoadInputState . fire ( historyEntry . state ) ;
167
165
if ( previous ) {
168
166
this . _inputEditor . setPosition ( { lineNumber : 1 , column : 1 } ) ;
169
167
} else {
@@ -196,8 +194,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
196
194
*/
197
195
async acceptInput ( userQuery ?: string , inputState ?: any ) : Promise < void > {
198
196
if ( userQuery ) {
199
- this . history . add ( userQuery ) ;
200
- this . historyStates . set ( userQuery , inputState ) ;
197
+ this . history . add ( { text : userQuery , state : inputState } ) ;
201
198
}
202
199
203
200
if ( this . accessibilityService . isScreenReaderOptimized ( ) && isMacintosh ) {
@@ -272,6 +269,10 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
272
269
const model = this . _inputEditor . getModel ( ) ;
273
270
const inputHasText = ! ! model && model . getValueLength ( ) > 0 ;
274
271
this . inputEditorHasText . set ( inputHasText ) ;
272
+ if ( ! this . onHistoryEntry ) {
273
+ this . historyNavigationForewardsEnablement . set ( ! inputHasText ) ;
274
+ this . historyNavigationBackwardsEnablement . set ( ! inputHasText ) ;
275
+ }
275
276
} ) ) ;
276
277
this . _register ( this . _inputEditor . onDidFocusEditorText ( ( ) => {
277
278
this . _onDidFocus . fire ( ) ;
@@ -289,9 +290,12 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
289
290
}
290
291
291
292
const atTop = e . position . column === 1 && e . position . lineNumber === 1 ;
292
- this . historyNavigationBackwardsEnablement . set ( atTop ) ;
293
293
this . chatCursorAtTop . set ( atTop ) ;
294
- this . historyNavigationForewardsEnablement . set ( e . position . equals ( getLastPosition ( model ) ) ) ;
294
+
295
+ if ( this . onHistoryEntry ) {
296
+ this . historyNavigationBackwardsEnablement . set ( atTop ) ;
297
+ this . historyNavigationForewardsEnablement . set ( e . position . equals ( getLastPosition ( model ) ) ) ;
298
+ }
295
299
} ) ) ;
296
300
297
301
this . toolbar = this . _register ( this . instantiationService . createInstance ( MenuWorkbenchToolBar , inputContainer , MenuId . ChatExecute , {
@@ -381,8 +385,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
381
385
382
386
saveState ( ) : void {
383
387
const inputHistory = this . history . getHistory ( ) ;
384
- const historyEntries = inputHistory . map ( entry => ( { text : entry , state : this . historyStates . get ( entry ) } ) ) ;
385
- this . historyService . saveHistory ( this . providerId ! , historyEntries ) ;
388
+ this . historyService . saveHistory ( this . providerId ! , inputHistory ) ;
386
389
}
387
390
}
388
391
0 commit comments