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

fix https://github.com/microsoft/vscode-copilot/issues/3187 #200233

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget } from 'vs
import { KeyCode } from 'vs/base/common/keyCodes';
import { localize } from 'vs/nls';
import * as aria from 'vs/base/browser/ui/aria/aria';
import { EditorOption } from 'vs/editor/common/config/editorOptions';

export class SlashCommandContentWidget extends Disposable implements IContentWidget {
private _domNode = document.createElement('div');
Expand All @@ -28,33 +29,48 @@ export class SlashCommandContentWidget extends Disposable implements IContentWid
}

override dispose() {
this._editor.removeContentWidget(this);
this.hide();
super.dispose();
}

show() {
if (this._isVisible) {
return;
if (!this._isVisible) {
this._isVisible = true;
this._domNode.toggleAttribute('hidden', false);
this._editor.addContentWidget(this);
}
this._isVisible = true;
this._domNode.toggleAttribute('hidden', false);
this._editor.addContentWidget(this);
}

hide() {
this._isVisible = false;
this._domNode.toggleAttribute('hidden', true);
this._editor.removeContentWidget(this);
if (this._isVisible) {
this._isVisible = false;
this._domNode.toggleAttribute('hidden', true);
this._editor.removeContentWidget(this);
}
}

setCommandText(slashCommand: string) {
this._domNode.innerText = `/${slashCommand} `;
this._lastSlashCommandText = slashCommand;
}

getId() { return 'chat-slash-command-content-widget'; }
getDomNode() { return this._domNode; }
getPosition() { return { position: { lineNumber: 1, column: 1 }, preference: [ContentWidgetPositionPreference.EXACT] }; }
getId() {
return 'chat-slash-command-content-widget';
}

getDomNode() {
return this._domNode;
}

getPosition() {
return { position: { lineNumber: 1, column: 1 }, preference: [ContentWidgetPositionPreference.EXACT] };
}

beforeRender(): null {
const lineHeight = this._editor.getOption(EditorOption.lineHeight);
this._domNode.style.lineHeight = `${lineHeight - 2 /*padding*/}px`;
return null;
}

private _handleKeyDown(e: IKeyboardEvent) {
if (e.keyCode !== KeyCode.Backspace) {
Expand Down