in client/src/cqlInput/popover/TypeaheadPopover.ts [59:107]
private updateRendererState: (state: PopoverRendererState) => void =
noopUpdateRendererState;
private _applySuggestion: (from: number, to: number, value: string) => void;
private _skipSuggestion: () => void;
private currentSuggestion: TypeaheadSuggestion | undefined;
private currentOptionIndex = 0;
private isPending = false;
public constructor(
private view: EditorView,
protected popoverEl: HTMLElement,
// Apply a suggestion to the input
applySuggestion: (from: number, to: number, value: string) => void,
// Skip a suggestion, and move on to the next valid field
skipSuggestion: () => void,
// A callback that receives everything necessary to render popover content
// as the input state changes.
renderPopoverContent: (args: PopoverRendererArgs) => void
) {
super(popoverEl);
this._applySuggestion = applySuggestion;
this._skipSuggestion = skipSuggestion;
renderPopoverContent({
applySuggestion: this.applySuggestion,
skipSuggestion: this.skipSuggestion,
subscribeToAction: this.actionSubscriber,
subscribeToState: this.stateSubscriber,
closePopover: this.hide,
popoverEl
})
// Prevent the popover from stealing focus from the input, unless we are
// focusing on another input within the popover
popoverEl.addEventListener("mousedown", (e) => {
if ((e.target as HTMLElement).tagName !== "INPUT") {
e.preventDefault();
}
});
// Close the popover when the input loses focus, unless we are focusing
// on an element within the popover
view.dom.addEventListener("blur", (e) => {
if (!popoverEl.contains(e.relatedTarget as HTMLElement)) {
this.hide();
}
});
}