Update src/editor/autocomplete to correctly call countCompletions and moveSelection

This commit is contained in:
Pierre Boyer 2019-06-04 13:21:39 +02:00
parent 97d4d1b73a
commit ed6427571e

View file

@ -42,31 +42,19 @@ export default class AutocompleteWrapperModel {
async onTab(e) { async onTab(e) {
const acComponent = this._getAutocompleterComponent(); const acComponent = this._getAutocompleterComponent();
if (acComponent.state.completionList.length === 0) { if (acComponent.countCompletions() === 0) {
// Force completions to show for the text currently entered // Force completions to show for the text currently entered
await acComponent.forceComplete(); await acComponent.forceComplete();
// Select the first item by moving "down" // Select the first item by moving "down"
await acComponent.onDownArrow(); await acComponent.moveSelection(+1);
} else { } else {
if (e.shiftKey) { await acComponent.moveSelection(e.shiftKey ? -1 : +1);
await acComponent.onUpArrow();
} else {
await acComponent.onDownArrow();
}
} }
this._updateCallback({ this._updateCallback({
close: true, close: true,
}); });
} }
onUpArrow() {
this._getAutocompleterComponent().onUpArrow();
}
onDownArrow() {
this._getAutocompleterComponent().onDownArrow();
}
onPartUpdate(part, offset) { onPartUpdate(part, offset) {
// cache the typed value and caret here // cache the typed value and caret here
// so we can restore it in onComponentSelectionChange when the value is undefined (meaning it should be the typed text) // so we can restore it in onComponentSelectionChange when the value is undefined (meaning it should be the typed text)