diff --git a/src/commandline_frame.ts b/src/commandline_frame.ts index 1c971382..8a91b1db 100644 --- a/src/commandline_frame.ts +++ b/src/commandline_frame.ts @@ -209,6 +209,13 @@ export function prev_completion() { if (activeCompletions) activeCompletions.forEach(comp => comp.prev()) } +/** + * Deselects the currently selected completion. + */ +export function deselect_completion() { + if (activeCompletions) activeCompletions.forEach(comp => comp.deselect()) +} + /** * Inserts the currently selected completion and a space in the command line. */ diff --git a/src/completions.ts b/src/completions.ts index 1b3c8420..037a00e6 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -36,6 +36,7 @@ export abstract class CompletionSource { node: HTMLElement public completion: string protected prefixes: string[] = [] + protected lastFocused: CompletionOption constructor(prefixes) { let commands = aliases.getCmdAliasMapping() @@ -78,6 +79,11 @@ export abstract class CompletionSource { prev(inc = 1): boolean { return this.next(-1 * inc) } + + deselect() { + this.completion = undefined + if (this.lastFocused != undefined) this.lastFocused.state = "normal" + } } // Default classes @@ -129,7 +135,6 @@ export abstract class CompletionSourceFuse extends CompletionSource { public node public options: CompletionOptionFuse[] protected lastExstr: string - protected lastFocused: CompletionOption protected optionContainer = html`