Skip to content

Commit

Permalink
Add "Shift+Space", "Backquote", and "None" to a `Select a suggestion …
Browse files Browse the repository at this point in the history
…key` option (#128)
  • Loading branch information
tadashi-aikawa committed Jun 4, 2022
1 parent 7874a09 commit f533bb4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
17 changes: 16 additions & 1 deletion src/option/SelectSuggestionKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ type Name =
| "Ctrl/Cmd+Enter"
| "Alt+Enter"
| "Shift+Enter"
| "Space";
| "Space"
| "Shift+Space"
| "Backquote"
| "None";
interface KeyBind {
modifiers: Modifier[];
key: string | null;
Expand Down Expand Up @@ -39,6 +42,18 @@ export class SelectSuggestionKey {
modifiers: [],
key: " ",
});
static readonly SHIFT_SPACE = new SelectSuggestionKey("Shift+Space", {
modifiers: ["Shift"],
key: " ",
});
static readonly BACKQUOTE = new SelectSuggestionKey("Backquote", {
modifiers: [],
key: "`",
});
static readonly None = new SelectSuggestionKey("None", {
modifiers: [],
key: "",
});

private constructor(readonly name: Name, readonly keyBind: KeyBind) {
SelectSuggestionKey._values.push(this);
Expand Down
22 changes: 12 additions & 10 deletions src/ui/AutoCompleteSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,18 @@ export class AutoCompleteSuggest
)
);
}
this.keymapEventHandler.push(
this.scope.register(
selectSuggestionKey.keyBind.modifiers,
selectSuggestionKey.keyBind.key,
() => {
this.suggestions.useSelectedItem({});
return false;
}
)
);
if (selectSuggestionKey !== SelectSuggestionKey.None) {
this.keymapEventHandler.push(
this.scope.register(
selectSuggestionKey.keyBind.modifiers,
selectSuggestionKey.keyBind.key,
() => {
this.suggestions.useSelectedItem({});
return false;
}
)
);
}

this.scope.keys.find((x) => x.key === "Escape")!.func = () => {
this.close();
Expand Down

0 comments on commit f533bb4

Please sign in to comment.