Skip to content

Commit

Permalink
clean-up keybindings and menu registrations for accept suggestion com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
jrieken committed Mar 10, 2022
1 parent c2b5174 commit 9109c65
Showing 1 changed file with 32 additions and 38 deletions.
70 changes: 32 additions & 38 deletions src/vs/editor/contrib/suggest/browser/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ import { SnippetParser } from 'vs/editor/contrib/snippet/browser/snippetParser';
import { ISuggestMemoryService } from 'vs/editor/contrib/suggest/browser/suggestMemory';
import { WordContextKey } from 'vs/editor/contrib/suggest/browser/wordContextKey';
import * as nls from 'vs/nls';
import { MenuRegistry } from 'vs/platform/actions/common/actions';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ILogService } from 'vs/platform/log/common/log';
import { CompletionItem, Context as SuggestContext, ISuggestItemPreselector, suggestWidgetStatusbarMenu } from './suggest';
import { SuggestAlternatives } from './suggestAlternatives';
Expand Down Expand Up @@ -728,44 +727,39 @@ registerEditorCommand(new SuggestCommand({
precondition: SuggestContext.Visible,
handler(x) {
x.acceptSelectedSuggestion(true, false);
}
},
kbOpts: [{
// normal tab
primary: KeyCode.Tab,
kbExpr: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus),
weight,
}, {
// accept on enter has special rules
primary: KeyCode.Enter,
kbExpr: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus, SuggestContext.AcceptSuggestionsOnEnter, SuggestContext.MakesTextEdit),
weight,
}],
menuOpts: [{
menuId: suggestWidgetStatusbarMenu,
title: nls.localize('accept.insert', "Insert"),
group: 'left',
order: 1,
when: SuggestContext.HasInsertAndReplaceRange.toNegated()
}, {
menuId: suggestWidgetStatusbarMenu,
title: nls.localize('accept.insert', "Insert"),
group: 'left',
order: 1,
when: ContextKeyExpr.and(SuggestContext.HasInsertAndReplaceRange, SuggestContext.InsertMode.isEqualTo('insert'))
}, {
menuId: suggestWidgetStatusbarMenu,
title: nls.localize('accept.replace', "Replace"),
group: 'left',
order: 1,
when: ContextKeyExpr.and(SuggestContext.HasInsertAndReplaceRange, SuggestContext.InsertMode.isEqualTo('replace'))
}]
}));

// normal tab
KeybindingsRegistry.registerKeybindingRule({
id: 'acceptSelectedSuggestion',
when: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus),
primary: KeyCode.Tab,
weight
});

// accept on enter has special rules
KeybindingsRegistry.registerKeybindingRule({
id: 'acceptSelectedSuggestion',
when: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus, SuggestContext.AcceptSuggestionsOnEnter, SuggestContext.MakesTextEdit),
primary: KeyCode.Enter,
weight,
});

MenuRegistry.appendMenuItem(suggestWidgetStatusbarMenu, {
command: { id: 'acceptSelectedSuggestion', title: nls.localize('accept.insert', "Insert") },
group: 'left',
order: 1,
when: SuggestContext.HasInsertAndReplaceRange.toNegated()
});
MenuRegistry.appendMenuItem(suggestWidgetStatusbarMenu, {
command: { id: 'acceptSelectedSuggestion', title: nls.localize('accept.insert', "Insert") },
group: 'left',
order: 1,
when: ContextKeyExpr.and(SuggestContext.HasInsertAndReplaceRange, SuggestContext.InsertMode.isEqualTo('insert'))
});
MenuRegistry.appendMenuItem(suggestWidgetStatusbarMenu, {
command: { id: 'acceptSelectedSuggestion', title: nls.localize('accept.replace', "Replace") },
group: 'left',
order: 1,
when: ContextKeyExpr.and(SuggestContext.HasInsertAndReplaceRange, SuggestContext.InsertMode.isEqualTo('replace'))
});

registerEditorCommand(new SuggestCommand({
id: 'acceptAlternativeSelectedSuggestion',
precondition: ContextKeyExpr.and(SuggestContext.Visible, EditorContextKeys.textInputFocus),
Expand Down

0 comments on commit 9109c65

Please sign in to comment.