update untitledHint, remove button
This commit is contained in:
parent
7f72823067
commit
2962e6ade1
2 changed files with 11 additions and 26 deletions
|
@ -8,7 +8,7 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
|||
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
|
||||
import { localize } from 'vs/nls';
|
||||
import { DEFAULT_FONT_FAMILY } from 'vs/workbench/browser/style';
|
||||
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { inputPlaceholderForeground, textLinkForeground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { ChangeModeAction } from 'vs/workbench/browser/parts/editor/editorStatus';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
|
@ -16,8 +16,6 @@ import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
|||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { FloatingClickWidget } from 'vs/workbench/browser/codeeditor';
|
||||
import { ITASExperimentService } from 'vs/workbench/services/experiment/common/experimentService';
|
||||
const $ = dom.$;
|
||||
|
||||
|
@ -28,16 +26,15 @@ export class UntitledHintContribution implements IEditorContribution {
|
|||
|
||||
private toDispose: IDisposable[];
|
||||
private untitledHintContentWidget: UntitledHintContentWidget | undefined;
|
||||
private button: FloatingClickWidget | undefined;
|
||||
private experimentTreatment: 'text' | 'button' | 'hidden' | undefined;
|
||||
private experimentTreatment: 'text' | 'hidden' | undefined;
|
||||
|
||||
|
||||
constructor(
|
||||
private editor: ICodeEditor,
|
||||
@ICommandService private readonly commandService: ICommandService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService,
|
||||
@IKeybindingService private readonly keybindingService: IKeybindingService,
|
||||
@IThemeService private readonly themeService: IThemeService,
|
||||
@ITASExperimentService private readonly experimentService: ITASExperimentService
|
||||
|
||||
) {
|
||||
this.toDispose = [];
|
||||
this.toDispose.push(this.editor.onDidChangeModel(() => this.update()));
|
||||
|
@ -47,7 +44,7 @@ export class UntitledHintContribution implements IEditorContribution {
|
|||
this.update();
|
||||
}
|
||||
}));
|
||||
this.experimentService.getTreatment<'text' | 'button'>('untitledhint').then(treatment => {
|
||||
this.experimentService.getTreatment<'text' | 'hidden'>('untitledhint').then(treatment => {
|
||||
this.experimentTreatment = treatment;
|
||||
this.update();
|
||||
});
|
||||
|
@ -55,25 +52,13 @@ export class UntitledHintContribution implements IEditorContribution {
|
|||
|
||||
private update(): void {
|
||||
this.untitledHintContentWidget?.dispose();
|
||||
this.button?.dispose();
|
||||
const configValue = this.configurationService.getValue<'text' | 'button' | 'hidden' | 'default'>(untitledHintSetting);
|
||||
const untitledHintMode = configValue === 'default' ? (this.experimentTreatment || 'hidden') : configValue;
|
||||
const configValue = this.configurationService.getValue<'text' | 'hidden' | 'default'>(untitledHintSetting);
|
||||
const untitledHintMode = configValue === 'default' ? (this.experimentTreatment || 'text') : configValue;
|
||||
|
||||
const model = this.editor.getModel();
|
||||
|
||||
if (model && model.uri.scheme === Schemas.untitled && model.getModeId() === PLAINTEXT_MODE_ID) {
|
||||
if (untitledHintMode === 'text') {
|
||||
this.untitledHintContentWidget = new UntitledHintContentWidget(this.editor, this.commandService, this.configurationService);
|
||||
}
|
||||
if (untitledHintMode === 'button') {
|
||||
this.button = new FloatingClickWidget(this.editor, localize('selectALanguage', "Select a Language"), null, this.keybindingService, this.themeService);
|
||||
this.toDispose.push(this.button.onClick(async () => {
|
||||
// Need to focus editor before so current editor becomes active and the command is properly executed
|
||||
this.editor.focus();
|
||||
await this.commandService.executeCommand(ChangeModeAction.ID, { from: 'button' });
|
||||
this.editor.focus();
|
||||
}));
|
||||
this.button.render();
|
||||
}
|
||||
if (model && model.uri.scheme === Schemas.untitled && model.getModeId() === PLAINTEXT_MODE_ID && untitledHintMode === 'text') {
|
||||
this.untitledHintContentWidget = new UntitledHintContentWidget(this.editor, this.commandService, this.configurationService);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ import { isStandalone } from 'vs/base/browser/browser';
|
|||
},
|
||||
'workbench.editor.untitled.hint': {
|
||||
'type': 'string',
|
||||
'enum': ['text', 'button', 'hidden', 'default'],
|
||||
'enum': ['text', 'hidden', 'default'],
|
||||
'default': 'default',
|
||||
'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 hint should be inline text in the editor or a floating button or hidden.")
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue