From 70b0382ecab29374e7dacb242c228bf74d041afd Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 24 Jan 2020 16:41:06 +0100 Subject: [PATCH] update statusbar with "real" keybindings --- .../contrib/suggest/suggestController.ts | 30 ++++++----- .../editor/contrib/suggest/suggestWidget.ts | 50 +++++++++++++------ 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/vs/editor/contrib/suggest/suggestController.ts b/src/vs/editor/contrib/suggest/suggestController.ts index 7507d316df1..f54f304688c 100644 --- a/src/vs/editor/contrib/suggest/suggestController.ts +++ b/src/vs/editor/contrib/suggest/suggestController.ts @@ -528,11 +528,8 @@ const SuggestCommand = EditorCommand.bindToContribution(Sugge registerEditorCommand(new SuggestCommand({ id: 'acceptSelectedSuggestion', precondition: SuggestContext.Visible, - handler(x, args) { - const alternative: boolean = typeof args === 'object' && typeof args.alternative === 'boolean' - ? args.alternative - : false; - x.acceptSelectedSuggestion(true, alternative); + handler(x) { + x.acceptSelectedSuggestion(true, false); } })); @@ -552,16 +549,23 @@ KeybindingsRegistry.registerKeybindingRule({ weight }); +// todo@joh control enablement via context key // shift+enter and shift+tab use the alternative-flag so that the suggest controller // is doing the opposite of the editor.suggest.overwriteOnAccept-configuration -KeybindingsRegistry.registerKeybindingRule({ - id: 'acceptSelectedSuggestion', - when: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus), - primary: KeyMod.Shift | KeyCode.Tab, - secondary: [KeyMod.Shift | KeyCode.Enter], - args: { alternative: true }, - weight -}); +registerEditorCommand(new SuggestCommand({ + id: 'acceptAlternativeSelectedSuggestion', + precondition: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus), + kbOpts: { + weight: weight, + kbExpr: EditorContextKeys.textInputFocus, + primary: KeyMod.Shift | KeyCode.Enter, + secondary: [KeyMod.Shift | KeyCode.Tab], + }, + handler(x) { + x.acceptSelectedSuggestion(false, true); + }, +})); + // continue to support the old command CommandsRegistry.registerCommandAlias('acceptSelectedSuggestionOnEnter', 'acceptSelectedSuggestion'); diff --git a/src/vs/editor/contrib/suggest/suggestWidget.ts b/src/vs/editor/contrib/suggest/suggestWidget.ts index 45aef8ce35d..95c1a8c24f9 100644 --- a/src/vs/editor/contrib/suggest/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/suggestWidget.ts @@ -42,13 +42,10 @@ import { FileKind } from 'vs/platform/files/common/files'; import { MarkdownString } from 'vs/base/common/htmlContent'; import { flatten } from 'vs/base/common/arrays'; import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; +import { Position } from 'vs/editor/common/core/position'; 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 { root: HTMLElement; @@ -306,7 +303,7 @@ class SuggestionDetails { private readonly widget: SuggestWidget, private readonly editor: ICodeEditor, private readonly markdownRenderer: MarkdownRenderer, - private readonly triggerKeybindingLabel: string, + private readonly kbToggleDetails: string, ) { this.disposables = new DisposableStore(); @@ -321,7 +318,7 @@ class SuggestionDetails { this.header = append(this.body, $('.header')); 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.docs = append(this.body, $('p.docs')); @@ -473,6 +470,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate toggleClass(this.element, 'no-icons', !this.editor.getOption(EditorOption.suggest).showIcons); 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], { useShadows: false, @@ -730,6 +732,22 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate 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) { this.currentSuggestionDetails.cancel(); @@ -767,9 +785,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate