Split ApplySelection into CompleteOrPrevSelection and CompleteOrNextSelection

When moving through the autocomplete selection list distinguish between
the following cases:
1) When there is no autocomplete window open, only open one and select
the first item when the CompleteOrPrevSelection /
CompleteOrNextSelection actions are emitted (e.g. by pressing SHIFT +
TAB, TAB)
2) Otherwise navigate through the selection list (e.g. SHIFT + TAB, TAB,
UP, DOWN)

- Remove references to raw keyboard events in autocomplete.ts
- Clarify the purpose of startSelection (previously onTab)

Signed-off-by: Clemens Zeidler <clemens.zeidler@gmail.com>
This commit is contained in:
Clemens Zeidler 2021-03-28 19:59:33 +13:00
parent 7d087524a5
commit 57cd8afbc4
4 changed files with 29 additions and 24 deletions

View file

@ -68,24 +68,24 @@ export default class AutocompleteWrapperModel {
this.updateCallback({close: true});
}
public async onTab(e: KeyboardEvent) {
/**
* If there is no current autocompletion, start one and move to the first selection.
*/
public async startSelection() {
const acComponent = this.getAutocompleterComponent();
if (acComponent.countCompletions() === 0) {
// Force completions to show for the text currently entered
await acComponent.forceComplete();
// Select the first item by moving "down"
await acComponent.moveSelection(+1);
} else {
await acComponent.moveSelection(e.shiftKey ? -1 : +1);
}
}
public onUpArrow(e: KeyboardEvent) {
public selectPreviousSelection() {
this.getAutocompleterComponent().moveSelection(-1);
}
public onDownArrow(e: KeyboardEvent) {
public selectNextSelection() {
this.getAutocompleterComponent().moveSelection(+1);
}