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

feat: show inline chat hint in empty text editors #192352

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/workbench.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
key: 'untitledLabelFormat'
}, "Controls the format of the label for an untitled editor."),
},
'workbench.editor.untitled.hint': {
'workbench.editor.empty.hint': {
'type': 'string',
'enum': ['text', 'hidden'],
'default': 'text',
'markdownDescription': localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'untitledHint' }, "Controls if the untitled text hint should be visible in the editor.")
'markdownDescription': localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'emptyEditorHint' }, "Controls if the empty editor text hint should be visible in the editor.")
},
'workbench.editor.languageDetection': {
type: 'boolean',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const enum AccessibilityVerbositySettingId {
Editor = 'accessibility.verbosity.editor',
Hover = 'accessibility.verbosity.hover',
Notification = 'accessibility.verbosity.notification',
EditorUntitledHint = 'accessibility.verbosity.untitledHint'
EmptyEditorHint = 'accessibility.verbosity.emptyEditorHint'
}

export const enum AccessibleViewProviderId {
Expand All @@ -56,7 +56,7 @@ export const enum AccessibleViewProviderId {
Editor = 'editor',
Hover = 'hover',
Notification = 'notification',
EditorUntitledHint = 'editor.untitledHint'
EmptyEditorHint = 'emptyEditorHint'
}

const baseProperty: object = {
Expand Down Expand Up @@ -106,8 +106,8 @@ const configuration: IConfigurationNode = {
description: localize('verbosity.notification', 'Provide information about how to open the notification in an accessible view.'),
...baseProperty
},
[AccessibilityVerbositySettingId.EditorUntitledHint]: {
description: localize('verbosity.untitledhint', 'Provide information about relevant actions in an untitled text editor.'),
[AccessibilityVerbositySettingId.EmptyEditorHint]: {
description: localize('verbosity.emptyEditorHint', 'Provide information about relevant actions in an empty text editor.'),
...baseProperty
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ import './toggleMultiCursorModifier';
import './toggleRenderControlCharacter';
import './toggleRenderWhitespace';
import './toggleWordWrap';
import './untitledTextEditorHint/untitledTextEditorHint';
import './emptyTextEditorHint/emptyTextEditorHint';
import './workbenchReferenceSearch';
import './editorLineNumberMenu';
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

.monaco-editor .contentWidgets .untitled-hint {
.monaco-editor .contentWidgets .empty-editor-hint {
color: var(--vscode-input-placeholderForeground);
}

.monaco-editor .contentWidgets .untitled-hint a {
.monaco-editor .contentWidgets .empty-editor-hint a {
color: var(--vscode-textLink-foreground)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import 'vs/css!./untitledTextEditorHint';
import 'vs/css!./emptyTextEditorHint';
import * as dom from 'vs/base/browser/dom';
import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
Expand All @@ -30,16 +30,33 @@ import { KeybindingLabel } from 'vs/base/browser/ui/keybindingLabel/keybindingLa
import { OS } from 'vs/base/common/platform';
import { status } from 'vs/base/browser/ui/aria/aria';
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions, IConfigurationMigrationRegistry } from 'vs/workbench/common/configuration';

const $ = dom.$;

const untitledTextEditorHintSetting = 'workbench.editor.untitled.hint';
export class UntitledTextEditorHintContribution implements IEditorContribution {

public static readonly ID = 'editor.contrib.untitledTextEditorHint';
// TODO@joyceerhl remove this after a few iterations
Registry.as<IConfigurationMigrationRegistry>(Extensions.ConfigurationMigration)
.registerConfigurationMigrations([{
key: 'workbench.editor.untitled.hint',
migrateFn: (value, _accessor) => ([
[emptyTextEditorHintSetting, { value }],
])
},
{
key: 'accessibility.verbosity.untitledHint',
migrateFn: (value, _accessor) => ([
[AccessibilityVerbositySettingId.EmptyEditorHint, { value }],
])
}]);

const emptyTextEditorHintSetting = 'workbench.editor.empty.hint';
export class EmptyTextEditorHintContribution implements IEditorContribution {

public static readonly ID = 'editor.contrib.emptyTextEditorHint';

private toDispose: IDisposable[];
private untitledTextHintContentWidget: UntitledTextEditorHintContentWidget | undefined;
private textHintContentWidget: EmptyTextEditorHintContentWidget | undefined;

constructor(
private readonly editor: ICodeEditor,
Expand All @@ -56,13 +73,13 @@ export class UntitledTextEditorHintContribution implements IEditorContribution {
this.toDispose.push(this.editor.onDidChangeModel(() => this.update()));
this.toDispose.push(this.editor.onDidChangeModelLanguage(() => this.update()));
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(untitledTextEditorHintSetting)) {
if (e.affectsConfiguration(emptyTextEditorHintSetting)) {
this.update();
}
}));
this.toDispose.push(inlineChatSessionService.onWillStartSession(editor => {
if (this.editor === editor) {
this.untitledTextHintContentWidget?.dispose();
this.textHintContentWidget?.dispose();
}
}));
this.toDispose.push(inlineChatSessionService.onDidEndSession(editor => {
Expand All @@ -73,15 +90,16 @@ export class UntitledTextEditorHintContribution implements IEditorContribution {
}

private update(): void {
this.untitledTextHintContentWidget?.dispose();
const configValue = this.configurationService.getValue(untitledTextEditorHintSetting);
this.textHintContentWidget?.dispose();
const configValue = this.configurationService.getValue(emptyTextEditorHintSetting);
const model = this.editor.getModel();

const inlineChatProviders = [...this.inlineChatService.getAllProvider()];
const shouldRenderEitherDefaultOrInlineChatHint = model?.getLanguageId() === PLAINTEXT_LANGUAGE_ID && !inlineChatProviders.length || inlineChatProviders.length > 0;
const shouldRenderInlineChatHint = inlineChatProviders.length > 0;
const shouldRenderDefaultHint = model?.getLanguageId() === PLAINTEXT_LANGUAGE_ID && !inlineChatProviders.length;

if (model && model.uri.scheme === Schemas.untitled && shouldRenderEitherDefaultOrInlineChatHint && configValue === 'text') {
this.untitledTextHintContentWidget = new UntitledTextEditorHintContentWidget(
if (model && (model.uri.scheme === Schemas.untitled && shouldRenderDefaultHint || shouldRenderInlineChatHint) && configValue !== 'hidden') {
this.textHintContentWidget = new EmptyTextEditorHintContentWidget(
this.editor,
this.editorGroupsService,
this.commandService,
Expand All @@ -96,13 +114,13 @@ export class UntitledTextEditorHintContribution implements IEditorContribution {

dispose(): void {
dispose(this.toDispose);
this.untitledTextHintContentWidget?.dispose();
this.textHintContentWidget?.dispose();
}
}

class UntitledTextEditorHintContentWidget implements IContentWidget {
class EmptyTextEditorHintContentWidget implements IContentWidget {

private static readonly ID = 'editor.widget.untitledHint';
private static readonly ID = 'editor.widget.emptyHint';

private domNode: HTMLElement | undefined;
private toDispose: DisposableStore;
Expand All @@ -129,7 +147,7 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {
}));
const onDidFocusEditorText = Event.debounce(this.editor.onDidFocusEditorText, () => undefined, 500);
this.toDispose.add(onDidFocusEditorText(() => {
if (this.editor.hasTextFocus() && this.isVisible && this.ariaLabel && this.configurationService.getValue(AccessibilityVerbositySettingId.EditorUntitledHint)) {
if (this.editor.hasTextFocus() && this.isVisible && this.ariaLabel && this.configurationService.getValue(AccessibilityVerbositySettingId.EmptyEditorHint)) {
status(this.ariaLabel);
}
}));
Expand All @@ -147,7 +165,7 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {
}

getId(): string {
return UntitledTextEditorHintContentWidget.ID;
return EmptyTextEditorHintContentWidget.ID;
}

private _getHintInlineChat(providers: IInlineChatSessionProvider[]) {
Expand Down Expand Up @@ -175,14 +193,14 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {
}
};

const hintElement = $('untitled-hint-text');
const hintElement = $('empty-hint-text');
hintElement.style.display = 'block';

const keybindingHint = this.keybindingService.lookupKeybinding(inlineChatId);
const keybindingHintLabel = keybindingHint?.getLabel();

if (keybindingHint && keybindingHintLabel) {
const actionPart = localize('untitledText', 'Press {0} to ask {1} to do something. ', keybindingHintLabel, providerName);
const actionPart = localize('emptyHintText', 'Press {0} to ask {1} to do something. ', keybindingHintLabel, providerName);

const [before, after] = actionPart.split(keybindingHintLabel).map((fragment) => {
const hintPart = $('a', undefined, fragment);
Expand All @@ -203,7 +221,7 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {

hintElement.appendChild(after);

const typeToDismiss = localize('untitledText2', 'Start typing to dismiss.');
const typeToDismiss = localize('emptyHintTextDismiss', 'Start typing to dismiss.');
const textHint2 = $('span', undefined, typeToDismiss);
textHint2.style.fontStyle = 'italic';
hintElement.appendChild(textHint2);
Expand Down Expand Up @@ -284,7 +302,7 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {
};

const dontShowOnClickOrTap = () => {
this.configurationService.updateValue(untitledTextEditorHintSetting, 'hidden');
this.configurationService.updateValue(emptyTextEditorHintSetting, 'hidden');
this.dispose();
this.editor.focus();
};
Expand Down Expand Up @@ -318,14 +336,14 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {

getDomNode(): HTMLElement {
if (!this.domNode) {
this.domNode = $('.untitled-hint');
this.domNode = $('.empty-editor-hint');
this.domNode.style.width = 'max-content';
this.domNode.style.paddingLeft = '4px';

const inlineChatProviders = [...this.inlineChatService.getAllProvider()];
const { hintElement, ariaLabel } = !inlineChatProviders.length ? this._getHintDefault() : this._getHintInlineChat(inlineChatProviders);
this.domNode.append(hintElement);
this.ariaLabel = ariaLabel.concat(localize('disableHint', ' Toggle {0} in settings to disable this hint.', AccessibilityVerbositySettingId.EditorUntitledHint));
this.ariaLabel = ariaLabel.concat(localize('disableHint', ' Toggle {0} in settings to disable this hint.', AccessibilityVerbositySettingId.EmptyEditorHint));

this.toDispose.add(dom.addDisposableListener(this.domNode, 'click', () => {
this.editor.focus();
Expand All @@ -350,4 +368,4 @@ class UntitledTextEditorHintContentWidget implements IContentWidget {
}
}

registerEditorContribution(UntitledTextEditorHintContribution.ID, UntitledTextEditorHintContribution, EditorContributionInstantiation.Eager); // eager because it needs to render a help message
registerEditorContribution(EmptyTextEditorHintContribution.ID, EmptyTextEditorHintContribution, EditorContributionInstantiation.Eager); // eager because it needs to render a help message