File tree 2 files changed +16
-6
lines changed
2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -2246,19 +2246,28 @@ namespace winrt::Microsoft::Terminal::Control::implementation
2246
2246
return winrt::hstring{ L" " };
2247
2247
};
2248
2248
2249
+ const auto currentCommand = _terminal->CurrentCommand ();
2250
+ const auto trimmedCurrentCommand = trimToHstring (currentCommand);
2251
+
2249
2252
for (const auto & commandInBuffer : bufferCommands)
2250
2253
{
2251
- if (const auto hstr {trimToHstring (commandInBuffer)} ; !hstr.empty () )
2254
+ if (const auto hstr{ trimToHstring (commandInBuffer) };
2255
+ (!hstr.empty () && hstr != trimmedCurrentCommand))
2252
2256
{
2253
2257
commands.push_back (hstr);
2254
2258
}
2255
2259
}
2256
2260
2257
- auto context = winrt::make_self<CommandHistoryContext>(std::move (commands));
2258
-
2259
- const auto currentCommand = _terminal->CurrentCommand ();
2260
- context->CurrentCommandline (trimToHstring (currentCommand));
2261
+ // If the very last thing in the list of recent commands, is exacly the
2262
+ // same as the current command, then let's not include it in the
2263
+ // history. It's literally the thing the user has typed, RIGHT now.
2264
+ if (commands.back () == trimmedCurrentCommand)
2265
+ {
2266
+ commands.pop_back ();
2267
+ }
2261
2268
2269
+ auto context = winrt::make_self<CommandHistoryContext>(std::move (commands));
2270
+ context->CurrentCommandline (trimmedCurrentCommand);
2262
2271
return *context;
2263
2272
}
2264
2273
Original file line number Diff line number Diff line change @@ -543,8 +543,8 @@ namespace ControlUnitTests
543
543
Log::Comment (L" Write 'Bar' to the command..." );
544
544
conn->WriteInput (L" Bar" );
545
545
{
546
- DebugBreak ();
547
546
auto historyContext{ core->CommandHistory () };
547
+ // Bar shouldn't be in the history, it should be the current command
548
548
VERIFY_ARE_EQUAL (1u , historyContext.History ().Size ());
549
549
VERIFY_ARE_EQUAL (L" Bar" , historyContext.CurrentCommandline ());
550
550
}
@@ -556,6 +556,7 @@ namespace ControlUnitTests
556
556
{
557
557
auto historyContext{ core->CommandHistory () };
558
558
VERIFY_ARE_EQUAL (1u , historyContext.History ().Size ());
559
+ // The current commandline is now empty
559
560
VERIFY_ARE_EQUAL (L" " , historyContext.CurrentCommandline ());
560
561
}
561
562
}
You can’t perform that action at this time.
0 commit comments