Skip to content

Commit

Permalink
minor UX improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
timkmecl committed Dec 7, 2022
1 parent 24b0ad1 commit 1be3ca3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 98 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{
"command": "chatgpt.ask",
"when": "editorTextFocus",
"group": "navigation"
"group": "chatgpt-menu-group@1"
}
]
}
Expand Down
36 changes: 18 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function activate(context: vscode.ExtensionContext) {
provider.setSessionToken(sessionToken);

context.subscriptions.push(
vscode.window.registerWebviewViewProvider(ChatGPTViewProvider.viewType, provider));
vscode.window.registerWebviewViewProvider(ChatGPTViewProvider.viewType, provider, {
webviewOptions: { retainContextWhenHidden: true }
})
);

let disposable2 = vscode.commands.registerCommand('chatgpt.ask', () => {
vscode.window.showInputBox({ prompt: 'What do you want to do?' }).then((value) => {
Expand Down Expand Up @@ -54,6 +57,7 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
private _chatGPTAPI?: ChatGPTAPI;

private _response?: string;
private _prompt?: string;

private _sessionToken?: string;

Expand Down Expand Up @@ -117,16 +121,10 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
}
}
});

// when extension panel opens shows the previous response again
webviewView.onDidChangeVisibility(e => {
if (this._view && this._view.visible) {
this._view.webview.postMessage({ type: 'addResponse', value: this._response });
}
});
}

public async search(prompt:string|undefined) {
this._prompt = prompt;
if (!prompt) {
prompt = '';
};
Expand All @@ -136,6 +134,14 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
this._newAPI();
}

// focus gpt activity from activity bar
if (!this._view) {
await vscode.commands.executeCommand('chatgpt.chatView.focus');
} else {
this._view?.show?.(true);
}


let response = '';

// Check if the ChatGPTAPI instance is signed in
Expand Down Expand Up @@ -171,15 +177,11 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
searchPrompt = prompt;
}

// focus gpt activity from activity bar
vscode.commands.executeCommand('workbench.view.extension.chatgpt');

// modify the input tag to show the search prompt as input value
if (this._view) {
this._view.webview.postMessage({ type: 'setPrompt', value: searchPrompt });
}

console.log("sendMessage");

// Make sure theprompt is shown
this._view?.webview.postMessage({ type: 'setPrompt', value: this._prompt });

// Send the search prompt to the ChatGPTAPI instance and store the response
response = await this._chatGPTAPI.sendMessage(searchPrompt, {
onProgress: (partialResponse) => {
Expand All @@ -193,8 +195,6 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
// Saves the response
this._response = response;

// console.log(response);

// Show the view and send a message to the webview with the response
if (this._view) {
this._view.show?.(true);
Expand Down
23 changes: 0 additions & 23 deletions src/test/runTest.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/test/suite/extension.test.ts

This file was deleted.

38 changes: 0 additions & 38 deletions src/test/suite/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@
"eslint-visitor-keys" "^3.3.0"

"@vscode/test-electron@^2.2.0":
"integrity" "sha512-xk2xrOTMG75/hxO8OVVZ+GErv9gmdZwOD8rEHV3ty3n1Joav2yFcfrmqD6Ukref27U13LEL8gVvSHzauGAK5nQ=="
"resolved" "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.2.0.tgz"
"version" "2.2.0"
"integrity" "sha512-DUdwSYVc9p/PbGveaq20dbAAXHfvdq4zQ24ILp6PKizOBxrOfMsOq8Vts5nMzeIo0CxtA/RxZLFyDv001PiUSg=="
"resolved" "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.2.1.tgz"
"version" "2.2.1"
dependencies:
"http-proxy-agent" "^4.0.1"
"https-proxy-agent" "^5.0.0"
Expand Down

0 comments on commit 1be3ca3

Please sign in to comment.