diff --git a/.gitignore b/.gitignore index dfeb137b..78005000 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ VendorLib/Breakpad/src/tools/mac/dump_syms/build DerivedData VendorLib/clang/lib/arc VendorLib/clang/lib/c++ + +.idea \ No newline at end of file diff --git a/package.json b/package.json index 4ef7c884..613599c1 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "flux": "^3.1.3", "jquery": "^3.4.0", "jquery-ui": "^1.13.0", - "marked": "^1.0.0", + "marked": "^4.0.10", "prop-types": "^15.7.2", "q": "^1.5.1", "raphael": "^2.1.0", diff --git a/src/js/sandbox/commands.js b/src/js/sandbox/commands.js index 3e04cf97..16c348d8 100644 --- a/src/js/sandbox/commands.js +++ b/src/js/sandbox/commands.js @@ -193,6 +193,7 @@ var getAllCommands = function() { return allCommands; }; +exports.getAllCommands = getAllCommands; exports.instantCommands = instantCommands; exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand'); diff --git a/src/js/util/debug.js b/src/js/util/debug.js index 227e6113..cdf4867d 100644 --- a/src/js/util/debug.js +++ b/src/js/util/debug.js @@ -29,6 +29,7 @@ var toGlobalize = { TreeCompare: require('../graph/treeCompare'), Level: require('../level'), Sandbox: require('../sandbox/'), + SandboxCommands: require('../sandbox/commands'), GitDemonstrationView: require('../views/gitDemonstrationView'), Markdown: require('marked'), LevelDropdownView: require('../views/levelDropdownView'), diff --git a/src/js/views/commandViews.js b/src/js/views/commandViews.js index b47d4bfa..65b0570d 100644 --- a/src/js/views/commandViews.js +++ b/src/js/views/commandViews.js @@ -1,4 +1,5 @@ var Backbone = require('backbone'); +const {getAllCommands} = require('../sandbox/commands'); var Main = require('../app'); var CommandLineStore = require('../stores/CommandLineStore'); @@ -7,6 +8,23 @@ var CommandLineActions = require('../actions/CommandLineActions'); var log = require('../log'); var keyboard = require('../util/keyboard'); +const allCommands = Object.keys(getAllCommands()); +// Lets push a few commands up in the suggestion order, +// which overrides the order from the exportj +const autoCompleteSuggestionOrder = [ + 'levels', // above "level" + 'help', // above help level since you might not be in a level + 'show solution', // above show goal since you start with a goal view + 'reset', // over reset solved + 'import level', // over import tree +]; + +const allCommandsSorted = autoCompleteSuggestionOrder.concat( + // add the rest that arent in the list above + allCommands.map(command => autoCompleteSuggestionOrder.indexOf(command) > 0 ? null : command) + .filter(command => !!command) +); + var CommandPromptView = Backbone.View.extend({ initialize: function() { Main.getEvents().on('commandSubmittedPassive', this.addToCommandHistory, this); @@ -49,13 +67,25 @@ 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){ + for(const c of allCommandsSorted){ + 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); }, diff --git a/src/style/main.css b/src/style/main.css index fed3616c..3f559adc 100644 --- a/src/style/main.css +++ b/src/style/main.css @@ -1287,3 +1287,12 @@ div.gitDemonstrationView { border-top-color: #9bcbeb; background: #9bcbeb; } + + + +#shadow{ + position: absolute; + bottom: 0px; + left: 21px; + opacity: 0.4; +} \ No newline at end of file diff --git a/src/template.index.html b/src/template.index.html index 8f35f91b..fdc01e76 100644 --- a/src/template.index.html +++ b/src/template.index.html @@ -407,6 +407,7 @@ $
+