Skip to content

Commit eadc914

Browse files
committedJan 14, 2024
Use full history entry object in history navigator
1 parent 9595f43 commit eadc914

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed
 

‎src/vs/workbench/contrib/chat/browser/chatInputPart.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_
3939
import { chatAgentLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
4040
import { IChatReplyFollowup } from 'vs/workbench/contrib/chat/common/chatService';
4141
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';
4343
import { getSimpleCodeEditorWidgetOptions, getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
4444
import { ChatSubmitEditorAction, ChatSubmitSecondaryAgentEditorAction } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
4545
import { IPosition } from 'vs/editor/common/core/position';
@@ -82,8 +82,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
8282
return this._inputEditor;
8383
}
8484

85-
private history: HistoryNavigator<string>;
86-
private historyStates: Map<string, any> = new Map();
85+
private history: HistoryNavigator<IChatHistoryEntry>;
8786
private historyNavigationBackwardsEnablement!: IContextKey<boolean>;
8887
private historyNavigationForewardsEnablement!: IContextKey<boolean>;
8988
private onHistoryEntry = false;
@@ -134,11 +133,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
134133
setState(providerId: string, inputValue: string | undefined): void {
135134
this.providerId = providerId;
136135
const history = this.historyService.getHistory(providerId);
137-
this.historyStates = new Map(history.map(h => [h.text, h.state]));
138-
const historyTexts: string[] = [];
139-
this.historyStates.forEach((_, str) => historyTexts.push(str));
140-
141-
this.history = new HistoryNavigator(historyTexts, 50);
136+
this.history = new HistoryNavigator(history, 50);
142137

143138
if (typeof inputValue === 'string') {
144139
this.setValue(inputValue);
@@ -158,15 +153,15 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
158153
}
159154

160155
private navigateHistory(previous: boolean): void {
161-
const historyInput = (previous ?
156+
const historyEntry = (previous ?
162157
(this.history.previous() ?? this.history.first()) : this.history.next())
163-
?? '';
158+
?? { text: '' };
164159

165160
this.onHistoryEntry = previous || this.history.current() !== null;
166161

167-
aria.status(historyInput);
168-
this.setValue(historyInput);
169-
this._onDidLoadInputState.fire(this.historyStates.get(historyInput));
162+
aria.status(historyEntry.text);
163+
this.setValue(historyEntry.text);
164+
this._onDidLoadInputState.fire(historyEntry.state);
170165
if (previous) {
171166
this._inputEditor.setPosition({ lineNumber: 1, column: 1 });
172167
} else {
@@ -199,8 +194,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
199194
*/
200195
async acceptInput(userQuery?: string, inputState?: any): Promise<void> {
201196
if (userQuery) {
202-
this.history.add(userQuery);
203-
this.historyStates.set(userQuery, inputState);
197+
this.history.add({ text: userQuery, state: inputState });
204198
}
205199

206200
if (this.accessibilityService.isScreenReaderOptimized() && isMacintosh) {
@@ -391,8 +385,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
391385

392386
saveState(): void {
393387
const inputHistory = this.history.getHistory();
394-
const historyEntries = inputHistory.map(entry => ({ text: entry, state: this.historyStates.get(entry) }));
395-
this.historyService.saveHistory(this.providerId!, historyEntries);
388+
this.historyService.saveHistory(this.providerId!, inputHistory);
396389
}
397390
}
398391

0 commit comments

Comments
 (0)