Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Accept/Reject/Next/Prev chat edit actions in notebooks #233875

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/vs/workbench/contrib/chat/browser/chatEditorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { hasUndecidedChatEditingResourceContextKey, IChatEditingService } from '
import { ChatContextKeys } from '../common/chatContextKeys.js';
import { isEqual } from '../../../../base/common/resources.js';
import { Range } from '../../../../editor/common/core/range.js';
import { getNotebookEditorFromEditorPane } from '../../notebook/browser/notebookBrowser.js';
import { ctxNotebookHasEditorModification } from '../../notebook/browser/chatEdit/notebookChatEditController.js';

abstract class NavigateAction extends Action2 {

Expand All @@ -36,7 +38,7 @@ abstract class NavigateAction extends Action2 {
? KeyMod.Alt | KeyCode.F5
: KeyMod.Alt | KeyMod.Shift | KeyCode.F5,
weight: KeybindingWeight.EditorContrib,
when: ContextKeyExpr.and(ctxHasEditorModification, EditorContextKeys.focus),
when: ContextKeyExpr.and(ContextKeyExpr.or(ctxHasEditorModification, ctxNotebookHasEditorModification), EditorContextKeys.focus),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ctxHasEditorModifcations only applies to regular editors & not notebooks, hence the new context var

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I can create new menu items and ensure these are disabled for notebooks.

},
f1: true,
menu: {
Expand Down Expand Up @@ -120,7 +122,7 @@ abstract class AcceptDiscardAction extends Action2 {
? localize2('accept2', 'Accept')
: localize2('discard2', 'Discard'),
category: CHAT_CATEGORY,
precondition: ContextKeyExpr.and(ChatContextKeys.requestInProgress.negate(), hasUndecidedChatEditingResourceContextKey, ctxHasEditorModification),
precondition: ContextKeyExpr.and(ChatContextKeys.requestInProgress.negate(), hasUndecidedChatEditingResourceContextKey, ContextKeyExpr.or(ctxHasEditorModification, ctxNotebookHasEditorModification)),
icon: accept
? Codicon.check
: Codicon.discard,
Expand All @@ -144,20 +146,24 @@ abstract class AcceptDiscardAction extends Action2 {
const chatEditingService = accessor.get(IChatEditingService);
const editorService = accessor.get(IEditorService);

const editor = editorService.activeTextEditorControl;
if (!isCodeEditor(editor) || !editor.hasModel()) {
let uri = getNotebookEditorFromEditorPane(editorService.activeEditorPane)?.textModel?.uri;
if (!uri) {
const editor = editorService.activeTextEditorControl;
uri = isCodeEditor(editor) && editor.hasModel() ? editor.getModel().uri : undefined;
}
if (!uri) {
return;
}

const session = chatEditingService.getEditingSession(editor.getModel().uri);
const session = chatEditingService.getEditingSession(uri);
if (!session) {
return;
}

if (this.accept) {
session.accept(editor.getModel().uri);
session.accept(uri);
} else {
session.reject(editor.getModel().uri);
session.reject(uri);
}
}
}
Expand Down
Loading