Skip to content

Commit edf58bb

Browse files
committed
History position is no bigger than the current length of a history
1 parent f3f829d commit edf58bb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webscopeio/react-console",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "React component that emulates console behaviour",
55
"author": "jvorcak",
66
"license": "MIT",

src/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default class ReactConsole extends React.Component<Props, State> {
107107
private onSubmit = async (e: any) => {
108108
e.preventDefault();
109109

110-
const inputString: string = this.state.input
110+
const inputString: string = this.state.input;
111111
if (inputString === null) {
112112
return
113113
}
@@ -356,7 +356,12 @@ export default class ReactConsole extends React.Component<Props, State> {
356356
*/
357357
private onKeyDown = (event: any) => {
358358
if (event.which === 38) { // key up
359-
const historyPosition = Math.max(0, this.state.historyPosition - 1);
359+
if(this.props.history === undefined) {
360+
return
361+
}
362+
363+
const currentPos = Math.min(this.state.historyPosition, this.props.history.length);
364+
const historyPosition = Math.max(0, currentPos - 1);
360365
this.setPreviewPosition(historyPosition);
361366
event.preventDefault()
362367
} else if (event.which === 40) {

0 commit comments

Comments
 (0)