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())
}
/**
* 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.
*/

View file

@ -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`<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) {
for (const prefix of this.prefixes) {
if (exstr.startsWith(prefix)) {

View file

@ -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"