accept/reject all

This commit is contained in:
Nate Sesti 2023-06-27 09:51:37 -07:00
parent 3ecd29eb60
commit 5dfd7b8ee8
3 changed files with 53 additions and 3 deletions

View file

@ -85,6 +85,16 @@
"command": "continue.rejectSuggestion",
"category": "Continue",
"title": "Reject Suggestion"
},
{
"command": "continue.acceptAllSuggestions",
"category": "Continue",
"title": "Accept All Suggestions"
},
{
"command": "continue.rejectAllSuggestions",
"category": "Continue",
"title": "Reject All Suggestions"
}
],
"keybindings": [
@ -107,6 +117,16 @@
"command": "continue.acceptSuggestion",
"mac": "shift+ctrl+enter",
"key": "shift+ctrl+enter"
},
{
"command": "continue.acceptAllSuggestions",
"mac": "shift+cmd+enter",
"key": "shift+ctrl+enter"
},
{
"command": "continue.rejectAllSuggestions",
"mac": "shift+cmd+backspace",
"key": "shift+ctrl+backspace"
}
],
"menus": {

View file

@ -10,6 +10,8 @@ import {
rejectSuggestionCommand,
suggestionDownCommand,
suggestionUpCommand,
acceptAllSuggestionsCommand,
rejectAllSuggestionsCommand,
} from "./suggestions";
import * as bridge from "./bridge";
import { debugPanelWebview, setupDebugPanel } from "./debugPanel";
@ -61,6 +63,8 @@ const commandsMap: { [command: string]: (...args: any) => any } = {
"continue.suggestionUp": suggestionUpCommand,
"continue.acceptSuggestion": acceptSuggestionCommand,
"continue.rejectSuggestion": rejectSuggestionCommand,
"continue.acceptAllSuggestions": acceptAllSuggestionsCommand,
"continue.rejectAllSuggestions": rejectAllSuggestionsCommand,
"continue.focusContinueInput": async () => {
vscode.commands.executeCommand("continue.continueGUIView.focus");
debugPanelWebview?.postMessage({

View file

@ -238,6 +238,26 @@ export function acceptSuggestionCommand(key: SuggestionRanges | null = null) {
selectSuggestion("selected", key);
}
function handleAllSuggestions(accept: boolean) {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
const editorUri = editor.document.uri.toString();
const suggestions = editorToSuggestions.get(editorUri);
if (!suggestions) return;
while (suggestions.length > 0) {
selectSuggestion(accept ? "new" : "old");
}
}
export function acceptAllSuggestionsCommand() {
handleAllSuggestions(true);
}
export function rejectAllSuggestionsCommand() {
handleAllSuggestions(false);
}
export async function rejectSuggestionCommand(
key: SuggestionRanges | null = null
) {
@ -292,9 +312,15 @@ export async function showSuggestion(
return new Promise((resolve, reject) => {
editor!
.edit((edit) => {
edit.insert(new vscode.Position(range.end.line, 0), suggestion + "\n");
})
.edit(
(edit) => {
edit.insert(
new vscode.Position(range.end.line, 0),
suggestion + "\n"
);
},
{ undoStopBefore: false, undoStopAfter: false }
)
.then(
(success) => {
if (success) {