Fix commandline history capping

This commit is contained in:
xconverge 2018-06-20 21:42:45 -07:00
parent 46a21c5a36
commit f2effcefab
2 changed files with 5 additions and 14 deletions

View File

@ -32,7 +32,7 @@ export class CommandLineHistory {
// resize array if necessary
if (this._history.length > configuration.history) {
this._history = this._history.slice(0, configuration.history);
this._history = this._history.slice(this._history.length - configuration.history);
}
this.save();
@ -41,7 +41,7 @@ export class CommandLineHistory {
public get(): string[] {
// resize array if necessary
if (this._history.length > configuration.history) {
this._history = this._history.slice(0, configuration.history);
this._history = this._history.slice(this._history.length - configuration.history);
}
return this._history;

View File

@ -66,12 +66,8 @@ suite('command-line history', () => {
let added_cmd: string = String(configuration.history);
run_cmds.push(added_cmd);
history.add(added_cmd);
assertArrayEquals(
run_cmds
.slice()
.splice(1, configuration.history),
history.get()
);
assertArrayEquals(run_cmds.slice(1), history.get());
});
test('add command that exists in history', async () => {
@ -107,11 +103,6 @@ suite('command-line history', () => {
history.add(cmd);
}
assertArrayEquals(
run_cmds
.slice()
.splice(run_cmds.length - 10),
history.get()
);
assertArrayEquals(run_cmds.slice(run_cmds.length - configuration.history), history.get());
});
});