diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index e94922d1a9fc..2f3939b16006 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -152,7 +152,7 @@ Selects the 1st person in the results of the `find` command. === Listing entered commands : `history` -Lists all the commands that you have entered in chronological order. + +Lists all the commands that you have entered in reverse chronological order. + Format: `history` === Clearing all entries : `clear` diff --git a/src/main/java/seedu/address/logic/commands/HistoryCommand.java b/src/main/java/seedu/address/logic/commands/HistoryCommand.java index cf5f38ffb670..b16218635835 100644 --- a/src/main/java/seedu/address/logic/commands/HistoryCommand.java +++ b/src/main/java/seedu/address/logic/commands/HistoryCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import java.util.Collections; import java.util.List; import seedu.address.logic.CommandHistory; @@ -13,7 +14,7 @@ public class HistoryCommand extends Command { public static final String COMMAND_WORD = "history"; - public static final String MESSAGE_SUCCESS = "Entered commands (from earliest to most recent):\n%1$s"; + public static final String MESSAGE_SUCCESS = "Entered commands (from most recent to earliest):\n%1$s"; public static final String MESSAGE_NO_HISTORY = "You have not yet entered any commands."; @Override @@ -24,6 +25,7 @@ public CommandResult execute() { return new CommandResult(MESSAGE_NO_HISTORY); } + Collections.reverse(previousCommands); return new CommandResult(String.format(MESSAGE_SUCCESS, String.join("\n", previousCommands))); } diff --git a/src/test/java/seedu/address/logic/commands/HistoryCommandTest.java b/src/test/java/seedu/address/logic/commands/HistoryCommandTest.java index 17952be1d061..8bdf3f75ffe2 100644 --- a/src/test/java/seedu/address/logic/commands/HistoryCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/HistoryCommandTest.java @@ -35,7 +35,7 @@ public void execute() { history.add(command3); String expectedMessage = String.format(HistoryCommand.MESSAGE_SUCCESS, - String.join("\n", command1, command2, command3)); + String.join("\n", command3, command2, command1)); assertCommandResult(historyCommand, expectedMessage); }