Skip to content

Commit debaabd

Browse files
Merge pull request #205 from AY2021S1-CS2103T-T12-1/branch-fix-command-history
Fix CommandHistory
2 parents fce280d + 717c7f8 commit debaabd

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/main/java/seedu/address/history/HistoryManager.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,11 @@ private boolean hasNextCommand() {
8787
@Override
8888
public void addToHistory(String command) {
8989
hasReturnedCurrentCommandBefore = false;
90-
if (hasNextCommand()) {
91-
// if there exist a next command,
92-
// copy commandHistory[0] to commandHistory[currentCommandIndex],
93-
// store it as the new commandHistory
94-
// and append the new command.
95-
commandHistory = commandHistory.subList(0, currentCommandIndex + 1);
96-
this.currentCommandIndex++;
97-
this.commandHistory.add(command);
98-
} else if (isLimitReached()) {
90+
if (isLimitReached()) {
9991
this.commandHistory.remove(0);
100-
this.commandHistory.add(command);
101-
} else {
102-
// when there is sufficient space for nextCommand to be added to history
103-
this.currentCommandIndex++;
104-
this.commandHistory.add(command);
10592
}
93+
this.commandHistory.add(command);
94+
this.currentCommandIndex = commandHistory.size() - 1;
10695
}
10796

10897
@Override

0 commit comments

Comments
 (0)