mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 17:27:22 +02:00
autocomplete implemented
This commit is contained in:
parent
ecb97070eb
commit
863d6cfd5e
5 changed files with 31 additions and 4 deletions
|
@ -193,6 +193,7 @@ var getAllCommands = function() {
|
|||
return allCommands;
|
||||
};
|
||||
|
||||
exports.getAllCommands = getAllCommands;
|
||||
exports.instantCommands = instantCommands;
|
||||
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');
|
||||
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue