-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for "Tasks" in the Suggestions UI #15664
Changes from all commits
c96799c
1449088
d3b5533
0bda66f
ccfc834
c97ac66
7404dc3
f361b6c
b0fa972
985fcdb
e785bfc
48e7348
026f342
ff5eead
2c66c32
d94183b
8feb909
f5909d9
4516b4b
a3c4776
7988d89
84a41b4
36b5759
f3796da
f4c310a
dc71f0c
c9e7156
5defde5
57a5327
a172f53
e2cc278
e544871
173a830
a21c815
20f5651
236912a
84a8dd2
442413f
9d5ef3a
cd2db82
22c94bf
28555a6
36b676a
b096469
4e46a63
6c778a6
172a298
dfd4e27
0c19591
db99537
363c092
4766b62
dea426a
62fb61d
dc4a832
19c1ed9
dd5458c
df92394
51046c5
2088d32
cc05133
11916fd
1c52862
837c544
3ea3860
d593fe1
f56d258
4c2499c
057098e
62863f1
a530ccc
920353a
3fc364c
fb40b5d
d4422bb
6575e5a
c71ba64
2cf9f41
b8d8f11
ad62ad8
2080b92
d3e572d
967261d
0c39b37
ca3f7d4
1a23198
741b773
434572a
12d2160
f10f14c
1a8275e
7ae4716
1720905
45a6e1d
8879a1f
27b3aac
73a96ad
7c3fd2a
3ee1f9b
ce70a37
0bb3a8f
f9a764e
a013020
0cf6475
902ee8e
8f0b6f8
4de9303
873d8d4
a21977b
ff5ce00
4449109
16492a7
9070557
2d54223
4cccc2d
1759213
c1339bc
a68f229
90238ac
ef7f563
2bceb92
4110f2c
b7f8b36
9bacdb1
a33af4f
dff4ae3
3748900
8767448
dd56c4b
f23c859
1e91a1c
f84d139
382983e
2772094
d4d635d
e0d7754
3be1201
54234a9
c9fb788
26c35f9
a6e80d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -709,23 +709,42 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation | |
|
||
winrt::hstring SuggestionsArgs::GenerateName() const | ||
{ | ||
auto base{ RS_(L"SuggestionsCommandKey") }; | ||
switch (Source()) | ||
std::wstringstream ss; | ||
ss << RS_(L"SuggestionsCommandKey").c_str(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we merged with the ss and the comment unresolved 😄 |
||
|
||
if (UseCommandline()) | ||
{ | ||
case SuggestionsSource::CommandHistory: | ||
base = RS_(L"SuggestionsCommandHistoryCommandKey"); | ||
ss << L", useCommandline:true"; | ||
} | ||
|
||
if (UseCommandline()) | ||
// All of the source values will leave a trailing ", " that we need to chop later: | ||
ss << L", source: "; | ||
const auto source = Source(); | ||
if (source == SuggestionsSource::All) | ||
{ | ||
return winrt::hstring{ | ||
fmt::format(L"{}, useCommandline:true", std::wstring_view(base)) | ||
}; | ||
ss << L"all, "; | ||
} | ||
else if (source == static_cast<SuggestionsSource>(0)) | ||
{ | ||
ss << L"none, "; | ||
} | ||
else | ||
{ | ||
return base; | ||
if (WI_IsFlagSet(source, SuggestionsSource::Tasks)) | ||
{ | ||
ss << L"tasks, "; | ||
} | ||
|
||
if (WI_IsFlagSet(source, SuggestionsSource::CommandHistory)) | ||
{ | ||
ss << L"commandHistory, "; | ||
} | ||
} | ||
// Chop off the last "," | ||
auto result = ss.str(); | ||
// use `resize`, to avoid duplicating the entire string. (substr doesn't create a view.) | ||
result.resize(result.size() - 2); | ||
return winrt::hstring{ result }; | ||
} | ||
|
||
winrt::hstring FindMatchArgs::GenerateName() const | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -931,4 +931,72 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation | |
{ | ||
return _ExpandedCommandsCache; | ||
} | ||
|
||
IVector<Model::Command> _filterToSendInput(IMapView<hstring, Model::Command> nameMap, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rude! this is not filtering, this is constructing a completely different set of commands. that's a different operation than filtering. |
||
winrt::hstring currentCommandline) | ||
{ | ||
auto results = winrt::single_threaded_vector<Model::Command>(); | ||
|
||
const auto numBackspaces = currentCommandline.size(); | ||
// Helper to clone a sendInput command into a new Command, with the | ||
// input trimmed to account for the currentCommandline | ||
auto createInputAction = [&](const Model::Command& command) -> Model::Command { | ||
winrt::com_ptr<implementation::Command> cmdImpl; | ||
cmdImpl.copy_from(winrt::get_self<implementation::Command>(command)); | ||
|
||
const auto inArgs{ command.ActionAndArgs().Args().try_as<Model::SendInputArgs>() }; | ||
|
||
auto args = winrt::make_self<SendInputArgs>( | ||
winrt::hstring{ fmt::format(FMT_COMPILE(L"{:\x7f^{}}{}"), | ||
L"", | ||
numBackspaces, | ||
(std::wstring_view)(inArgs ? inArgs.Input() : L"")) }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW does this really work? I didn't think strict ternary operators allowed this. I thought it would have needed to be something like this: inArgs ? std::wstring_view{ inArgs.Input() } : std::wstring_view{} so that each arm of the ternary has the exact same type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seemed like it compiled and ran fine? Now that I look at it, it does feel weird that it compiles. I feel like usually the compiler is much more strict about this kind of thing... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's because the hstring gets implicitly turned into a C string. The string-view constructor will then do a strlen to turn it back. That's not particularly optimal, but we also won't die from that. 😅 |
||
Model::ActionAndArgs actionAndArgs{ ShortcutAction::SendInput, *args }; | ||
|
||
auto copy = cmdImpl->Copy(); | ||
copy->ActionAndArgs(actionAndArgs); | ||
|
||
return *copy; | ||
}; | ||
|
||
// iterate over all the commands in all our actions... | ||
for (auto&& [name, command] : nameMap) | ||
{ | ||
// If this is not a nested command, and it's a sendInput command... | ||
if (!command.HasNestedCommands() && | ||
command.ActionAndArgs().Action() == ShortcutAction::SendInput) | ||
{ | ||
// copy it into the results. | ||
results.Append(createInputAction(command)); | ||
} | ||
// If this is nested... | ||
else if (command.HasNestedCommands()) | ||
{ | ||
// Look for any sendInput commands nested underneath us | ||
auto innerResults = _filterToSendInput(command.NestedCommands(), currentCommandline); | ||
|
||
if (innerResults.Size() > 0) | ||
{ | ||
// This command did have at least one sendInput under it | ||
|
||
// Create a new Command, which is a copy of this Command, | ||
// which only has SendInputs in it | ||
winrt::com_ptr<implementation::Command> cmdImpl; | ||
cmdImpl.copy_from(winrt::get_self<implementation::Command>(command)); | ||
auto copy = cmdImpl->Copy(); | ||
copy->NestedCommands(innerResults.GetView()); | ||
|
||
results.Append(*copy); | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
IVector<Model::Command> ActionMap::FilterToSendInput( | ||
winrt::hstring currentCommandline) | ||
{ | ||
return _filterToSendInput(NameMap(), currentCommandline); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,16 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation | |
return _subcommands ? _subcommands.GetView() : nullptr; | ||
} | ||
|
||
void Command::NestedCommands(const Windows::Foundation::Collections::IVectorView<Model::Command>& nested) | ||
{ | ||
_subcommands = winrt::single_threaded_map<winrt::hstring, Model::Command>(); | ||
|
||
for (const auto& n : nested) | ||
{ | ||
_subcommands.Insert(n.Name(), n); | ||
} | ||
Comment on lines
+69
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I forgot to mark this one for the |
||
} | ||
|
||
// Function Description: | ||
// - reports if the current command has nested commands | ||
// - This CANNOT detect { "name": "foo", "commands": null } | ||
|
@@ -752,7 +762,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation | |
// Iterate in reverse over the history, so that most recent commands are first | ||
for (auto i = history.Size(); i > 0; i--) | ||
{ | ||
std::wstring_view line{ history.GetAt(i - 1) }; | ||
const auto& element{ history.GetAt(i - 1) }; | ||
std::wstring_view line{ element }; | ||
|
||
if (line.empty()) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, didn't we make a change on your other suggestions PR to use
sender
instead ofactive control
?