提交 70b0382e 编写于 作者: J Johannes Rieken

update statusbar with "real" keybindings

上级 d413a30a
...@@ -528,11 +528,8 @@ const SuggestCommand = EditorCommand.bindToContribution<SuggestController>(Sugge ...@@ -528,11 +528,8 @@ const SuggestCommand = EditorCommand.bindToContribution<SuggestController>(Sugge
registerEditorCommand(new SuggestCommand({ registerEditorCommand(new SuggestCommand({
id: 'acceptSelectedSuggestion', id: 'acceptSelectedSuggestion',
precondition: SuggestContext.Visible, precondition: SuggestContext.Visible,
handler(x, args) { handler(x) {
const alternative: boolean = typeof args === 'object' && typeof args.alternative === 'boolean' x.acceptSelectedSuggestion(true, false);
? args.alternative
: false;
x.acceptSelectedSuggestion(true, alternative);
} }
})); }));
...@@ -552,16 +549,23 @@ KeybindingsRegistry.registerKeybindingRule({ ...@@ -552,16 +549,23 @@ KeybindingsRegistry.registerKeybindingRule({
weight weight
}); });
// todo@joh control enablement via context key
// shift+enter and shift+tab use the alternative-flag so that the suggest controller // shift+enter and shift+tab use the alternative-flag so that the suggest controller
// is doing the opposite of the editor.suggest.overwriteOnAccept-configuration // is doing the opposite of the editor.suggest.overwriteOnAccept-configuration
KeybindingsRegistry.registerKeybindingRule({ registerEditorCommand(new SuggestCommand({
id: 'acceptSelectedSuggestion', id: 'acceptAlternativeSelectedSuggestion',
when: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus), precondition: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus),
primary: KeyMod.Shift | KeyCode.Tab, kbOpts: {
secondary: [KeyMod.Shift | KeyCode.Enter], weight: weight,
args: { alternative: true }, kbExpr: EditorContextKeys.textInputFocus,
weight primary: KeyMod.Shift | KeyCode.Enter,
}); secondary: [KeyMod.Shift | KeyCode.Tab],
},
handler(x) {
x.acceptSelectedSuggestion(false, true);
},
}));
// continue to support the old command // continue to support the old command
CommandsRegistry.registerCommandAlias('acceptSelectedSuggestionOnEnter', 'acceptSelectedSuggestion'); CommandsRegistry.registerCommandAlias('acceptSelectedSuggestionOnEnter', 'acceptSelectedSuggestion');
......
...@@ -42,13 +42,10 @@ import { FileKind } from 'vs/platform/files/common/files'; ...@@ -42,13 +42,10 @@ import { FileKind } from 'vs/platform/files/common/files';
import { MarkdownString } from 'vs/base/common/htmlContent'; import { MarkdownString } from 'vs/base/common/htmlContent';
import { flatten } from 'vs/base/common/arrays'; import { flatten } from 'vs/base/common/arrays';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { Position } from 'vs/editor/common/core/position';
const expandSuggestionDocsByDefault = false; const expandSuggestionDocsByDefault = false;
const READ_MORE_TEXT = nls.localize('suggestWidget.readMore', 'Read more... (⌃Space)');
const READ_LESS_TEXT = nls.localize('suggestWidget.readLess', 'Read less... (⌃Space)');
const INSERT_REPLACE_TEXT = nls.localize('suggestWidget.insertOrReplace', 'Enter to insert, Tab to replace');
interface ISuggestionTemplateData { interface ISuggestionTemplateData {
root: HTMLElement; root: HTMLElement;
...@@ -306,7 +303,7 @@ class SuggestionDetails { ...@@ -306,7 +303,7 @@ class SuggestionDetails {
private readonly widget: SuggestWidget, private readonly widget: SuggestWidget,
private readonly editor: ICodeEditor, private readonly editor: ICodeEditor,
private readonly markdownRenderer: MarkdownRenderer, private readonly markdownRenderer: MarkdownRenderer,
private readonly triggerKeybindingLabel: string, private readonly kbToggleDetails: string,
) { ) {
this.disposables = new DisposableStore(); this.disposables = new DisposableStore();
...@@ -321,7 +318,7 @@ class SuggestionDetails { ...@@ -321,7 +318,7 @@ class SuggestionDetails {
this.header = append(this.body, $('.header')); this.header = append(this.body, $('.header'));
this.close = append(this.header, $('span.codicon.codicon-close')); this.close = append(this.header, $('span.codicon.codicon-close'));
this.close.title = nls.localize('readLess', "Read less...{0}", this.triggerKeybindingLabel); this.close.title = nls.localize('readLess', "Read less...{0}", this.kbToggleDetails);
this.type = append(this.header, $('p.type')); this.type = append(this.header, $('p.type'));
this.docs = append(this.body, $('p.docs')); this.docs = append(this.body, $('p.docs'));
...@@ -473,6 +470,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -473,6 +470,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
readonly allowEditorOverflow = true; readonly allowEditorOverflow = true;
readonly suppressMouseDown = false; readonly suppressMouseDown = false;
private readonly msgDetailMore: string;
private readonly msgDetailsLess: string;
private state: State | null = null; private state: State | null = null;
private isAuto: boolean = false; private isAuto: boolean = false;
private loadingTimeout: IDisposable = Disposable.None; private loadingTimeout: IDisposable = Disposable.None;
...@@ -525,18 +525,20 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -525,18 +525,20 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
constructor( constructor(
private readonly editor: ICodeEditor, private readonly editor: ICodeEditor,
@ITelemetryService private readonly telemetryService: ITelemetryService, @ITelemetryService private readonly telemetryService: ITelemetryService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IContextKeyService contextKeyService: IContextKeyService, @IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService, @IStorageService storageService: IStorageService,
@IKeybindingService keybindingService: IKeybindingService,
@IModeService modeService: IModeService, @IModeService modeService: IModeService,
@IOpenerService openerService: IOpenerService, @IOpenerService openerService: IOpenerService,
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
) { ) {
const kb = keybindingService.lookupKeybinding('editor.action.triggerSuggest');
const triggerKeybindingLabel = !kb ? '' : ` (${kb.getLabel()})`;
const markdownRenderer = this.toDispose.add(new MarkdownRenderer(editor, modeService, openerService)); const markdownRenderer = this.toDispose.add(new MarkdownRenderer(editor, modeService, openerService));
const kbToggleDetails = keybindingService.lookupKeybinding('toggleSuggestionDetails')?.getLabel() ?? '';
this.msgDetailsLess = nls.localize('detail.less', "{0} for less...", kbToggleDetails);
this.msgDetailMore = nls.localize('detail.more', "{0} for more...", kbToggleDetails);
this.isAuto = false; this.isAuto = false;
this.focusedItem = null; this.focusedItem = null;
this.storageService = storageService; this.storageService = storageService;
...@@ -558,15 +560,15 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -558,15 +560,15 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
this.statusBarLeftSpan = append(this.statusBarElement, $('span')); this.statusBarLeftSpan = append(this.statusBarElement, $('span'));
this.statusBarRightSpan = append(this.statusBarElement, $('span')); this.statusBarRightSpan = append(this.statusBarElement, $('span'));
this.setStatusBarLeftText(INSERT_REPLACE_TEXT); this.setStatusBarLeftText('');
this.setStatusBarRightText(''); this.setStatusBarRightText('');
this.details = instantiationService.createInstance(SuggestionDetails, this.element, this, this.editor, markdownRenderer, triggerKeybindingLabel); this.details = instantiationService.createInstance(SuggestionDetails, this.element, this, this.editor, markdownRenderer, kbToggleDetails);
const applyIconStyle = () => toggleClass(this.element, 'no-icons', !this.editor.getOption(EditorOption.suggest).showIcons); const applyIconStyle = () => toggleClass(this.element, 'no-icons', !this.editor.getOption(EditorOption.suggest).showIcons);
applyIconStyle(); applyIconStyle();
let renderer = instantiationService.createInstance(ItemRenderer, this, this.editor, triggerKeybindingLabel); let renderer = instantiationService.createInstance(ItemRenderer, this, this.editor, kbToggleDetails);
this.list = new List('SuggestWidget', this.listElement, this, [renderer], { this.list = new List('SuggestWidget', this.listElement, this, [renderer], {
useShadows: false, useShadows: false,
...@@ -730,6 +732,22 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -730,6 +732,22 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
this.firstFocusInCurrentList = !this.focusedItem; this.firstFocusInCurrentList = !this.focusedItem;
if (item !== this.focusedItem) { if (item !== this.focusedItem) {
// update statusbar
// todo@joh,pine -> this should a toolbar with actions so that these things become
// mouse clickable and fit for accessibility...
const wantsInsert = this.editor.getOption(EditorOption.suggest).insertMode === 'insert';
const kbAccept = this.keybindingService.lookupKeybinding('acceptSelectedSuggestion')?.getLabel();
const kbAcceptAlt = this.keybindingService.lookupKeybinding('acceptAlternativeSelectedSuggestion')?.getLabel();
if (!Position.equals(item.editInsertEnd, item.editReplaceEnd)) {
// insert AND replace
if (wantsInsert) {
this.setStatusBarLeftText(nls.localize('insert', "{0} to insert, {1} to replace", kbAccept, kbAcceptAlt));
} else {
this.setStatusBarLeftText(nls.localize('replace', "{0} to replace, {1} to insert", kbAccept, kbAcceptAlt));
}
} else {
this.setStatusBarLeftText(nls.localize('accept', "{0} to accept", kbAccept));
}
if (this.currentSuggestionDetails) { if (this.currentSuggestionDetails) {
this.currentSuggestionDetails.cancel(); this.currentSuggestionDetails.cancel();
...@@ -767,9 +785,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -767,9 +785,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
if (canExpandCompletionItem(this.focusedItem)) { if (canExpandCompletionItem(this.focusedItem)) {
if (this.expandDocsSettingFromStorage()) { if (this.expandDocsSettingFromStorage()) {
this.setStatusBarRightText(READ_LESS_TEXT); this.setStatusBarRightText(this.msgDetailsLess);
} else { } else {
this.setStatusBarRightText(READ_MORE_TEXT); this.setStatusBarRightText(this.msgDetailMore);
} }
} else { } else {
this.statusBarRightSpan.innerText = ''; this.statusBarRightSpan.innerText = '';
...@@ -1044,7 +1062,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -1044,7 +1062,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
removeClass(this.element, 'docs-side'); removeClass(this.element, 'docs-side');
removeClass(this.element, 'docs-below'); removeClass(this.element, 'docs-below');
this.editor.layoutContentWidget(this); this.editor.layoutContentWidget(this);
this.setStatusBarRightText(READ_MORE_TEXT); this.setStatusBarRightText(this.msgDetailMore);
this.telemetryService.publicLog2('suggestWidget:collapseDetails'); this.telemetryService.publicLog2('suggestWidget:collapseDetails');
} else { } else {
if (this.state !== State.Open && this.state !== State.Details && this.state !== State.Frozen) { if (this.state !== State.Open && this.state !== State.Details && this.state !== State.Frozen) {
...@@ -1053,7 +1071,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl ...@@ -1053,7 +1071,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
this.updateExpandDocsSetting(true); this.updateExpandDocsSetting(true);
this.showDetails(false); this.showDetails(false);
this.setStatusBarRightText(READ_LESS_TEXT); this.setStatusBarRightText(this.msgDetailsLess);
this.telemetryService.publicLog2('suggestWidget:expandDetails'); this.telemetryService.publicLog2('suggestWidget:expandDetails');
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册