diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 03f69625d..be16f2f1b 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -1241,6 +1241,13 @@ namespace winrt::TerminalApp::implementation IVector CommandPalette::_loadRecentCommands() { const auto recentCommands = ApplicationState::SharedInstance().RecentCommands(); + // If this is the first time we've opened the commandline mode and + // there aren't any recent commands, then just return an empty vector. + if (!recentCommands) + { + return single_threaded_vector(); + } + std::vector parsedCommands; parsedCommands.reserve(std::min(recentCommands.Size(), CommandLineHistoryLength)); @@ -1268,7 +1275,9 @@ namespace winrt::TerminalApp::implementation void CommandPalette::_updateRecentCommands(const hstring& command) { const auto recentCommands = ApplicationState::SharedInstance().RecentCommands(); - const auto countToCopy = std::min(recentCommands.Size(), CommandLineHistoryLength - 1); + // If there aren't and recent commands already in the state, then we + // don't need to copy any. + const auto countToCopy = std::min(recentCommands ? recentCommands.Size() : 0, CommandLineHistoryLength - 1); std::vector newRecentCommands{ countToCopy + 1 }; til::at(newRecentCommands, 0) = command; if (countToCopy)