Fix command history navigation

This commit is contained in:
boryslevytskyi
2017-05-13 23:48:46 +03:00
parent c550d46f86
commit b6a2205d98
3 changed files with 40 additions and 7 deletions

View File

@@ -5,7 +5,7 @@ export default class InputBox extends React.Component {
constructor() {
super();
this.history = [];
this.historyIndex = 0;
this.historyIndex = -1;
}
componentDidMount(){
@@ -29,16 +29,21 @@ export default class InputBox extends React.Component {
var value = input.value;
this.history.unshift(value);
this.historyIndex = -1;
input.value = '';
cmd.execute(value);
console.log(this.history);
}
onKeyDown(args) {
if(args.keyCode == 38) {
if (this.history.length > this.historyIndex) { // up
args.target.value = this.history[this.historyIndex++];
if(args.keyCode == 38) {
var newIndex = this.historyIndex+1;
if (this.history.length > newIndex) { // up
args.target.value = this.history[newIndex];
this.historyIndex = newIndex;
}
args.preventDefault();
@@ -46,8 +51,7 @@ export default class InputBox extends React.Component {
}
if(args.keyCode == 40) {
if(this.historyIndex > 0) { // up
if(this.historyIndex > 0) { // down
args.target.value = this.history[--this.historyIndex];
}

View File

@@ -252,4 +252,22 @@ export class Expression {
};
}
export var parser = expression;
export var parser = expression;
export class Parser {
constructor(input, pos) {
this.input = input;
this.pos = pos || 0;
this.buffer = [];
}
parse() {
console.log(this.input.length);
while(this.pos<this.input.length) {
this.buffer.push(this.input[this.pos]);
this.pos++;
}
console.log('exit');
}
}

11
tests/unit/parserSpec.js Normal file
View File

@@ -0,0 +1,11 @@
var expression = require('../../src/app/expression');
var parser = new expression.Parser();
describe("Parser", function() {
it("should be able to parse from start", function() {
var sut = new expression.Parser("test", 0);
sut.parse();
console.log(sut);
});
});