Skip to content

Commit f7152e2

Browse files
authored
button to 'restore to last checkpoint (microsoft#256896)
* add restore last checkpoint' button * change wording * use find
1 parent 0958948 commit f7152e2

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function registerChatTitleActions() {
142142
menu: [{
143143
id: MenuId.ChatMessageFooter,
144144
group: 'navigation',
145-
order: 3,
145+
order: 4,
146146
when: ContextKeyExpr.and(ChatContextKeys.responseSupportsIssueReporting, ChatContextKeys.isResponse, ContextKeyExpr.has(enableFeedbackConfig))
147147
}, {
148148
id: MENU_INLINE_CHAT_WIDGET_SECONDARY,

src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingActions.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,61 @@ registerAction2(class RestoreCheckpointAction extends Action2 {
474474
}
475475
});
476476

477+
registerAction2(class RestoreLastCheckpoint extends Action2 {
478+
constructor() {
479+
super({
480+
id: 'workbench.action.chat.restoreLastCheckpoint',
481+
title: localize2('chat.restoreLastCheckpoint.label', "Restore to last checkpoint"),
482+
f1: false,
483+
category: CHAT_CATEGORY,
484+
icon: Codicon.arrowUp,
485+
menu: [
486+
{
487+
id: MenuId.ChatMessageFooter,
488+
group: 'navigation',
489+
order: 3,
490+
when: ContextKeyExpr.and(ContextKeyExpr.in(ChatContextKeys.itemId.key, ChatContextKeys.lastItemId.key), ContextKeyExpr.equals(`config.${ChatConfiguration.CheckpointsEnabled}`, true)),
491+
}
492+
]
493+
});
494+
}
495+
496+
async run(accessor: ServicesAccessor, ...args: any[]) {
497+
let item: ChatTreeItem | undefined = args[0];
498+
const chatWidgetService = accessor.get(IChatWidgetService);
499+
const chatService = accessor.get(IChatService);
500+
const widget = chatWidgetService.lastFocusedWidget;
501+
if (!isResponseVM(item) && !isRequestVM(item)) {
502+
item = widget?.getFocus();
503+
}
504+
505+
if (!item) {
506+
return;
507+
}
508+
509+
const chatModel = chatService.getSession(item.sessionId);
510+
if (!chatModel) {
511+
return;
512+
}
513+
514+
const session = chatModel.editingSession;
515+
if (!session) {
516+
return;
517+
}
518+
519+
await restoreSnapshotWithConfirmation(accessor, item);
520+
521+
if (isResponseVM(item)) {
522+
widget?.viewModel?.model.setCheckpoint(item.requestId);
523+
const request = chatModel.getRequests().find(request => request.id === item.requestId);
524+
if (request) {
525+
widget?.focusInput();
526+
widget?.input.setValue(request.message.text, false);
527+
}
528+
}
529+
}
530+
});
531+
477532
registerAction2(class EditAction extends Action2 {
478533
constructor() {
479534
super({

0 commit comments

Comments
 (0)