Merge pull request #936 from hong4rc/fix/autocomplete

fix: autocomplete show right shadow content and support multiple command
This commit is contained in:
Peter Cottle 2022-02-25 08:50:24 -07:00 committed by GitHub
commit 4faa16bcca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,12 +70,17 @@ var CommandPromptView = Backbone.View.extend({
var el = e.target;
const shadowEl = document.querySelector('#shadow');
const uc = el.value.replace(/ {2,}/g, ' ');
const currentValue = el.value;
const allCommand = currentValue.split(';');
const lastCommand = allCommand[allCommand.length - 1]
.replace(/\s\s+/g, ' ').replace(/^\s/, '');
shadowEl.innerHTML = '';
if(uc.length){
for(const c of allCommandsSorted){
if(c.indexOf(uc) === 0){
shadowEl.innerHTML = c;
if (lastCommand.length) {
for (const c of allCommandsSorted) {
if (c.startsWith(lastCommand)) {
shadowEl.innerHTML = (currentValue + c.replace(lastCommand, '')).replace(/ /g, ' ');
break;
}
}
@ -83,7 +88,9 @@ var CommandPromptView = Backbone.View.extend({
if (e.keyCode === 9) {
e.preventDefault();
el.value = shadowEl.innerHTML;
if (shadowEl.innerHTML) {
el.value = shadowEl.innerHTML.replace(/ /g, ' ');
}
}
this.updatePrompt(el);