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`` @@ -197,11 +202,6 @@ export abstract class CompletionSourceFuse extends CompletionSource { } } - deselect() { - this.completion = undefined - if (this.lastFocused != undefined) this.lastFocused.state = "normal" - } - splitOnPrefix(exstr: string) { for (const prefix of this.prefixes) { if (exstr.startsWith(prefix)) { diff --git a/src/excmds.ts b/src/excmds.ts index a5d95392..9b743e24 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -2606,14 +2606,15 @@ export async function fillcmdline_tmp(ms: number, ...strarr: string[]) { /** @hidden **/ const cmdframe_fns: { [key: string]: [string, any[]] } = { accept_line: ["accept_line", []], - next_history: ["next_history", []], - prev_history: ["prev_history", []], - next_completion: ["next_completion", []], - prev_completion: ["prev_completion", []], + complete: ["complete", []], + deselect_completion: ["deselect_completion", []], + hide_and_clear: ["hide_and_clear", []], insert_completion: ["insert_completion", []], insert_space_or_completion: ["insert_space_or_completion", []], - complete: ["complete", []], - hide_and_clear: ["hide_and_clear", []], + next_completion: ["next_completion", []], + next_history: ["next_history", []], + prev_completion: ["prev_completion", []], + prev_history: ["prev_history", []], } import * as tri_editor from "@src/lib/editor"