@@ -1454,15 +1454,17 @@ namespace winrt::TerminalApp::implementation
1454
1454
const auto source = realArgs.Source ();
1455
1455
std::vector<Command> commandsCollection;
1456
1456
Control::CommandHistoryContext context{ nullptr };
1457
- winrt::hstring currentCommandline;
1458
1457
winrt::hstring currentWorkingDirectory;
1458
+ winrt::hstring filter;
1459
+
1460
+ bool sortResults = source == SuggestionsSource::Scrollback;
1459
1461
1460
1462
// If the user wanted to use the current commandline to filter results,
1461
1463
// OR they wanted command history (or some other source that
1462
1464
// requires context from the control)
1463
1465
// then get that here.
1464
1466
const bool shouldGetContext = realArgs.UseCommandline () ||
1465
- WI_IsAnyFlagSet (source, SuggestionsSource::CommandHistory | SuggestionsSource::QuickFixes);
1467
+ WI_IsAnyFlagSet (source, SuggestionsSource::CommandHistory | SuggestionsSource::QuickFixes | SuggestionsSource::Scrollback );
1466
1468
if (const auto & control{ _GetActiveControl () })
1467
1469
{
1468
1470
currentWorkingDirectory = control.CurrentWorkingDirectory ();
@@ -1472,7 +1474,9 @@ namespace winrt::TerminalApp::implementation
1472
1474
context = control.CommandHistory ();
1473
1475
if (context)
1474
1476
{
1475
- currentCommandline = context.CurrentCommandline ();
1477
+ winrt::hstring currentCommandline = context.CurrentCommandline ();
1478
+ winrt::hstring currentWordPrefix = context.CurrentWordPrefix ();
1479
+ filter = source == SuggestionsSource::Scrollback ? currentWordPrefix : currentCommandline;
1476
1480
}
1477
1481
}
1478
1482
}
@@ -1496,7 +1500,7 @@ namespace winrt::TerminalApp::implementation
1496
1500
// their settings file. Ask the ActionMap for those.
1497
1501
if (WI_IsFlagSet (source, SuggestionsSource::Tasks))
1498
1502
{
1499
- const auto tasks = co_await _settings.GlobalSettings ().ActionMap ().FilterToSnippets (currentCommandline , currentWorkingDirectory);
1503
+ const auto tasks = co_await _settings.GlobalSettings ().ActionMap ().FilterToSnippets (filter , currentWorkingDirectory);
1500
1504
// ----- we may be on a background thread here -----
1501
1505
for (const auto & t : tasks)
1502
1506
{
@@ -1510,20 +1514,41 @@ namespace winrt::TerminalApp::implementation
1510
1514
if (WI_IsFlagSet (source, SuggestionsSource::CommandHistory) &&
1511
1515
context != nullptr )
1512
1516
{
1513
- const auto recentCommands = Command::HistoryToCommands (context.History (), currentCommandline , false , hstring{ L" \ue81c " });
1517
+ const auto recentCommands = Command::HistoryToCommands (context.History (), filter , false , hstring{ L" \ue81c " });
1514
1518
for (const auto & t : recentCommands)
1515
1519
{
1516
1520
commandsCollection.push_back (t);
1517
1521
}
1518
1522
}
1519
1523
1524
+ // Don't add this to All, or figure out a way to make it experimental
1525
+ if (source == SuggestionsSource::Scrollback)
1526
+ {
1527
+ if (const auto termControl{_GetActiveControl ()})
1528
+ {
1529
+ const auto scrollBackResults = termControl.SuggestionScrollBackSearch (realArgs.Regex ());
1530
+
1531
+ std::unordered_set<winrt::hstring> seen;
1532
+ seen.reserve (scrollBackResults.Size ());
1533
+ for (auto r : scrollBackResults)
1534
+ {
1535
+ if (seen.insert (r.Text ).second )
1536
+ {
1537
+ auto c = Command::ScrollBackSuggestionToCommand (r.Text , filter, r.Row );
1538
+ commandsCollection.push_back (c);
1539
+ }
1540
+ }
1541
+ }
1542
+ }
1543
+
1520
1544
co_await wil::resume_foreground (Dispatcher ());
1521
1545
1522
1546
// Open the palette with all these commands in it.
1523
1547
_OpenSuggestions (_GetActiveControl (),
1524
1548
winrt::single_threaded_vector<Command>(std::move (commandsCollection)),
1525
1549
SuggestionsMode::Palette,
1526
- currentCommandline);
1550
+ filter,
1551
+ sortResults);
1527
1552
}
1528
1553
1529
1554
void TerminalPage::_HandleColorSelection (const IInspectable& /* sender*/ ,
0 commit comments