Implement deselect_completion ex command

Left unbound by default.
This commit is contained in:
glacambre 2019-02-28 18:27:21 +01:00
parent 24228b8937
commit bdd3e04199
No known key found for this signature in database
GPG key ID: B9625DB1767553AC
3 changed files with 20 additions and 12 deletions

View file

@ -209,6 +209,13 @@ export function prev_completion() {
if (activeCompletions) activeCompletions.forEach(comp => comp.prev()) 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. * Inserts the currently selected completion and a space in the command line.
*/ */

View file

@ -36,6 +36,7 @@ export abstract class CompletionSource {
node: HTMLElement node: HTMLElement
public completion: string public completion: string
protected prefixes: string[] = [] protected prefixes: string[] = []
protected lastFocused: CompletionOption
constructor(prefixes) { constructor(prefixes) {
let commands = aliases.getCmdAliasMapping() let commands = aliases.getCmdAliasMapping()
@ -78,6 +79,11 @@ export abstract class CompletionSource {
prev(inc = 1): boolean { prev(inc = 1): boolean {
return this.next(-1 * inc) return this.next(-1 * inc)
} }
deselect() {
this.completion = undefined
if (this.lastFocused != undefined) this.lastFocused.state = "normal"
}
} }
// Default classes // Default classes
@ -129,7 +135,6 @@ export abstract class CompletionSourceFuse extends CompletionSource {
public node public node
public options: CompletionOptionFuse[] public options: CompletionOptionFuse[]
protected lastExstr: string protected lastExstr: string
protected lastFocused: CompletionOption
protected optionContainer = html`<table class="optionContainer">` protected optionContainer = html`<table class="optionContainer">`
@ -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) { splitOnPrefix(exstr: string) {
for (const prefix of this.prefixes) { for (const prefix of this.prefixes) {
if (exstr.startsWith(prefix)) { if (exstr.startsWith(prefix)) {

View file

@ -2606,14 +2606,15 @@ export async function fillcmdline_tmp(ms: number, ...strarr: string[]) {
/** @hidden **/ /** @hidden **/
const cmdframe_fns: { [key: string]: [string, any[]] } = { const cmdframe_fns: { [key: string]: [string, any[]] } = {
accept_line: ["accept_line", []], accept_line: ["accept_line", []],
next_history: ["next_history", []], complete: ["complete", []],
prev_history: ["prev_history", []], deselect_completion: ["deselect_completion", []],
next_completion: ["next_completion", []], hide_and_clear: ["hide_and_clear", []],
prev_completion: ["prev_completion", []],
insert_completion: ["insert_completion", []], insert_completion: ["insert_completion", []],
insert_space_or_completion: ["insert_space_or_completion", []], insert_space_or_completion: ["insert_space_or_completion", []],
complete: ["complete", []], next_completion: ["next_completion", []],
hide_and_clear: ["hide_and_clear", []], next_history: ["next_history", []],
prev_completion: ["prev_completion", []],
prev_history: ["prev_history", []],
} }
import * as tri_editor from "@src/lib/editor" import * as tri_editor from "@src/lib/editor"