diff --git a/web/app/sketcher/sketcher-app.js b/web/app/sketcher/sketcher-app.js index eb9109b3..e2ea5fb1 100644 --- a/web/app/sketcher/sketcher-app.js +++ b/web/app/sketcher/sketcher-app.js @@ -1,5 +1,6 @@ import {Viewer} from './viewer2d.js' import * as ui from '../ui/ui' +import {Terminal} from '../ui/terminal' import {IO, BBox} from './io' import {AddDimTool, AddCircleDimTool, HDimension, VDimension, Dimension, DiameterDimension} from './shapes/dim' import {AddPointTool, AddSegmentTool} from './shapes/segment' @@ -46,7 +47,7 @@ function App2D() { $('.coordinates-info').text(coord.x.toFixed(3) + " : " + coord.y.toFixed(3)); }); this.terminalHandeler = null; - this.terminal = new ui.Terminal(this.commandsWin, (command) => this.handleTerminalInput(command), () => this.getAllCommandList()); + this.terminal = new Terminal(this.commandsWin, (command) => this.handleTerminalInput(command), () => this.getAllCommandList()); this.bindToolsToTerminal(); @@ -367,7 +368,6 @@ App2D.prototype.getSketchId = function() { }; App2D.prototype.bindToolsToTerminal = function() { - }; App2D.STATIC_COMMANDS = { @@ -391,7 +391,7 @@ App2D.prototype.handleTerminalInput = function(commandStr) { if (cmd) { return cmd(this); } - let actionId = this.commands[cmd]; + let actionId = this.commands[commandStr]; if (actionId) { this.actions[actionId].action(); } else { diff --git a/web/app/ui/terminal.js b/web/app/ui/terminal.js new file mode 100644 index 00000000..ab10d5a1 --- /dev/null +++ b/web/app/ui/terminal.js @@ -0,0 +1,87 @@ +export function Terminal(win, commandProcessor, variantsSupplier) { + this.win = win; + this.out = win.root.find('.terminal-output'); + const input = win.root.find('.terminal-input input'); + + win.onShowCallback = function() { + input.focus(); + }; + this.history = []; + this.historyPointer = 0; + const setHistory = () => { + if (this.history.length == 0) return; + input.val(this.history[this.historyPointer]); + }; + + + input.keydown((e) => { + function consumeEvent() { + e.preventDefault(); + e.stopPropagation(); + } + if (e.keyCode == 9) { + const text = input.val(); + let variants = variantsSupplier().filter(v => v.startsWith(text)); + variants.sort(); + if (variants.length == 0) { + } else { + const shared = sharedStartOfSortedArray(variants); + if (shared.length != text.length) { + input.val(shared); + } else { + let autocompleteArea = this.out.find('.autocomplete-area'); + if (autocompleteArea.length == 0) { + autocompleteArea = $('