fix: right shadow and support multiple command

This commit is contained in:
Anh Hồng 2022-02-25 16:06:01 +07:00
parent 28c5df664a
commit 208d7e3038

View file

@ -70,12 +70,17 @@ var CommandPromptView = Backbone.View.extend({
var el = e.target; var el = e.target;
const shadowEl = document.querySelector('#shadow'); 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 = ''; shadowEl.innerHTML = '';
if(uc.length){ if (lastCommand.length) {
for (const c of allCommandsSorted) { for (const c of allCommandsSorted) {
if(c.indexOf(uc) === 0){ if (c.startsWith(lastCommand)) {
shadowEl.innerHTML = c; shadowEl.innerHTML = (currentValue + c.replace(lastCommand, '')).replace(/ /g, ' ');
break; break;
} }
} }
@ -83,7 +88,7 @@ var CommandPromptView = Backbone.View.extend({
if (e.keyCode === 9) { if (e.keyCode === 9) {
e.preventDefault(); e.preventDefault();
el.value = shadowEl.innerHTML; el.value = shadowEl.innerHTML.replace(/ /g, ' ');
} }
this.updatePrompt(el); this.updatePrompt(el);