Merge pull request #1147 from glacambre/fix_commandline_space

Fix commandline failing to insert spaces in middle of words
This commit is contained in:
Oliver Blanthorn 2018-11-06 09:08:44 +00:00 committed by GitHub
commit 3bdd795e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

View file

@ -164,6 +164,7 @@ export function complete() {
let matches = state.cmdHistory.filter(key => key.startsWith(fragment))
let mostrecent = matches[matches.length - 1]
if (mostrecent != undefined) clInput.value = mostrecent
clInput.dispatchEvent(new Event("input")) // dirty hack for completions
}
/**
@ -182,13 +183,31 @@ export function prev_completion() {
/**
* Inserts the currently selected completion and a space in the command line.
* If no completion option is selected, inserts a space in the command line.
*/
export function insert_completion() {
const command = getCompletion()
activeCompletions.forEach(comp => (comp.completion = undefined))
if (command) clInput.value = command
clInput.value += " "
if (command) {
clInput.value = command + " "
clInput.dispatchEvent(new Event("input")) // dirty hack for completions
}
}
/**
* If a completion is selected, inserts it in the command line with a space.
* If no completion is selected, inserts a space where the caret is.
*/
export function insert_space_or_completion() {
const command = getCompletion()
activeCompletions.forEach(comp => (comp.completion = undefined))
if (command) {
clInput.value = command + " "
} else {
const selectionStart = clInput.selectionStart
const selectionEnd = clInput.selectionEnd
clInput.value = clInput.value.substring(0, selectionStart) + " " + clInput.value.substring(selectionEnd)
clInput.selectionStart = clInput.selectionEnd = selectionStart + 1
}
clInput.dispatchEvent(new Event("input")) // dirty hack for completions
}
@ -401,6 +420,7 @@ export function getContent() {
export function editor_function(fn_name) {
if (tri_editor[fn_name]) {
tri_editor[fn_name](clInput)
clInput.dispatchEvent(new Event("input")) // dirty hack for completions
} else {
// The user is using the command line so we can't log message there
// logger.error(`No editor function named ${fn_name}!`)

View file

@ -2441,6 +2441,7 @@ const cmdframe_fns: { [key: string]: [string, any[]] } = {
next_completion: ["next_completion", []],
prev_completion: ["prev_completion", []],
insert_completion: ["insert_completion", []],
insert_space_or_completion: ["insert_space_or_completion", []],
complete: ["complete", []],
hide_and_clear: ["hide_and_clear", []],
}

View file

@ -86,7 +86,7 @@ class default_config {
"<C-f>": "ex.complete",
"<Tab>": "ex.next_completion",
"<S-Tab>": "ex.prev_completion",
"<Space>": "ex.insert_completion",
"<Space>": "ex.insert_space_or_completion",
}
/**