Skip to content

Commit ff5ca24

Browse files
authored
fix(completion): Add editor.acceptSuggestionOnTab setting (#3547)
__Issue:__ It's not straightforward to disable the `<tab>` key behavior of completion __Fix:__ Add an `editor.acceptSuggestionOnTab` setting, which is similar to the `editor.acceptSuggestionOnEnter` setting.
1 parent da91d49 commit ff5ca24

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

CHANGES_CURRENT.md

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
- #3533 - Completion: Fix hang when detail text is large
8787
- #3537 - Terminal: Fix pasted text showing in reverse order (fixes #3513)
8888
- #3541 - Pane: Shoudl grab focus when clicked (fixes #3538)
89+
- #3547 - Completion: Add `editor.acceptSuggestionOnTab` setting
8990

9091
### Performance
9192

docs/docs/configuration/settings.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc
2323

2424
### Editor
2525

26-
- `editor.acceptSuggestionOnEnter` __(_bool_ default: `false`)__ - When `true`, the enter key can be used to select a suggestion. By default, the enter key will not be used, so as not to interfere with creating a new line.
26+
- `editor.acceptSuggestionOnEnter` __(_bool_ default: `true`)__ - When `true`, the enter key can be used to accept a suggestion. Users may wish to set to `false` to avoid a conflict with inserting a new line.
27+
28+
- `editor.acceptSuggestionOnTab` __(_bool_ default: `true`)__ - When `true`, the tab key can be used to accept a suggestion. Users may wish to turn to `false` to avoid ambiguity with inserting a tab character.
2729

2830
- `editor.autoClosingBrackets` __(_"LanguageDefined"|"Never"_ default: `"LanguageDefined"`)__ - When set to `"LanguageDefined"`, Onivim will automatically close brackets and pairs, based on language configuration.
2931

src/Feature/LanguageSupport/Completion.re

+17-2
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ type model = {
454454
isInsertMode: bool,
455455
isSnippetMode: bool,
456456
acceptOnEnter: bool,
457+
acceptOnTab: bool,
457458
snippetSortOrder: [ | `Bottom | `Hidden | `Inline | `Top],
458459
isShadowEnabled: bool,
459460
isAnimationEnabled: bool,
@@ -463,6 +464,7 @@ let initial = {
463464
isInsertMode: false,
464465
isSnippetMode: false,
465466
acceptOnEnter: false,
467+
acceptOnTab: true,
466468
providers: [
467469
Session.create(
468470
~triggerCharacters=[],
@@ -494,6 +496,7 @@ let configurationChanged = (~config, model) => {
494496
{
495497
...model,
496498
acceptOnEnter: CompletionConfig.acceptSuggestionOnEnter.get(config),
499+
acceptOnTab: CompletionConfig.acceptSuggestionOnTab.get(config),
497500
snippetSortOrder: CompletionConfig.snippetSuggestions.get(config),
498501
isAnimationEnabled:
499502
Feature_Configuration.GlobalConfiguration.animation.get(config),
@@ -1012,6 +1015,9 @@ module ContextKeys = {
10121015

10131016
let acceptSuggestionOnEnter =
10141017
bool("acceptSuggestionOnEnter", model => model.acceptOnEnter);
1018+
1019+
let acceptSuggestionOnTab =
1020+
bool("acceptSuggestionOnTab", model => model.acceptOnTab);
10151021
};
10161022

10171023
// KEYBINDINGS
@@ -1025,6 +1031,10 @@ module KeyBindings = {
10251031
"acceptSuggestionOnEnter && suggestWidgetVisible && editorTextFocus"
10261032
|> WhenExpr.parse;
10271033

1034+
let acceptOnTab =
1035+
"acceptSuggestionOnTab && suggestWidgetVisible && editorTextFocus"
1036+
|> WhenExpr.parse;
1037+
10281038
let triggerSuggestCondition =
10291039
"editorTextFocus && insertMode && !suggestWidgetVisible" |> WhenExpr.parse;
10301040

@@ -1085,7 +1095,7 @@ module KeyBindings = {
10851095
bind(
10861096
~key="<TAB>",
10871097
~command=Commands.acceptSelected.id,
1088-
~condition=suggestWidgetVisible,
1098+
~condition=acceptOnTab,
10891099
);
10901100

10911101
let acceptSuggestionShiftTab =
@@ -1111,6 +1121,7 @@ module Contributions = {
11111121
quickSuggestions.spec,
11121122
wordBasedSuggestions.spec,
11131123
acceptSuggestionOnEnter.spec,
1124+
acceptSuggestionOnTab.spec,
11141125
snippetSuggestions.spec,
11151126
];
11161127

@@ -1123,7 +1134,11 @@ module Contributions = {
11231134
];
11241135

11251136
let contextKeys =
1126-
ContextKeys.[acceptSuggestionOnEnter, suggestWidgetVisible];
1137+
ContextKeys.[
1138+
acceptSuggestionOnTab,
1139+
acceptSuggestionOnEnter,
1140+
suggestWidgetVisible,
1141+
];
11271142

11281143
let keybindings =
11291144
KeyBindings.[

src/Feature/LanguageSupport/CompletionConfig.re

+10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ let acceptSuggestionOnEnter =
154154
~default=true,
155155
);
156156

157+
let acceptSuggestionOnTab =
158+
setting(
159+
"editor.acceptSuggestionOnTab",
160+
custom(
161+
~decode=Decode.AcceptSuggestionOnEnter.decode,
162+
~encode=Json.Encode.bool,
163+
),
164+
~default=true,
165+
);
166+
157167
let snippetSuggestions =
158168
setting(
159169
"editor.snippetSuggestions",

0 commit comments

Comments
 (0)