autocomplete implemented

This commit is contained in:
Amir Kabiri 2022-02-11 11:24:17 +03:30
parent ecb97070eb
commit 863d6cfd5e
5 changed files with 31 additions and 4 deletions

2
.gitignore vendored
View file

@ -49,3 +49,5 @@ VendorLib/Breakpad/src/tools/mac/dump_syms/build
DerivedData
VendorLib/clang/lib/arc
VendorLib/clang/lib/c++
.idea

View file

@ -193,6 +193,7 @@ var getAllCommands = function() {
return allCommands;
};
exports.getAllCommands = getAllCommands;
exports.instantCommands = instantCommands;
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');

View file

@ -1,4 +1,5 @@
var Backbone = require('backbone');
const {getAllCommands} = require('../sandbox/commands');
var Main = require('../app');
var CommandLineStore = require('../stores/CommandLineStore');
@ -49,13 +50,26 @@ var CommandPromptView = Backbone.View.extend({
},
onKeyDown: function(e) {
// If its a tab, prevent losing focus
var el = e.target;
const shadowEl = document.querySelector('#shadow');
const uc = el.value.replace(/ {2,}/g, ' ');
shadowEl.innerHTML = '';
if(uc.length){
const commands = Object.keys(getAllCommands());
for(const c of commands){
if(c.indexOf(uc) === 0){
shadowEl.innerHTML = c;
break;
}
}
}
if (e.keyCode === 9) {
e.preventDefault();
// Maybe one day do tab completion or something? :O
return;
el.value = shadowEl.innerHTML;
}
var el = e.target;
this.updatePrompt(el);
},

View file

@ -1287,3 +1287,12 @@ div.gitDemonstrationView {
border-top-color: #9bcbeb;
background: #9bcbeb;
}
#shadow{
position: absolute;
bottom: 0px;
left: 21px;
opacity: 0.4;
}

View file

@ -407,6 +407,7 @@
<span class="promptSign box">$</span>
<span class="cursor box">&nbsp;</span>
<p class="command"></p>
<div id="shadow"></div>
</div>
<textarea
autocomplete="off"