mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-15 16:32:43 +01:00
Fix command history navigation
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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
11
tests/unit/parserSpec.js
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user