Skip to content
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

Merged
merged 141 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
c96799c
Preview the input via the TSF input control. This is awesome, and sho…
zadjii-msft Mar 22, 2022
1449088
bugfixes for the demo
zadjii-msft Apr 1, 2022
d3b5533
fix remaining bugs
zadjii-msft Apr 29, 2022
0bda66f
a comment I missed
zadjii-msft Apr 29, 2022
ccfc834
Migrate spelling-0.0.21 changes from main
DHowett Apr 29, 2022
c97ac66
resart with fresh plumbing
zadjii-msft Feb 9, 2023
7404dc3
zhu li, do the thing
zadjii-msft Feb 10, 2023
f361b6c
lots of removal of dead code from the sxnui
zadjii-msft Feb 10, 2023
b0fa972
make the menu mode compact, and remove the search box
zadjii-msft Feb 12, 2023
985fcdb
better UX for typing
zadjii-msft Feb 12, 2023
e785bfc
Merge branch 'main' into dev/migrie/f/12861-preview-input
zadjii-msft Feb 16, 2023
48e7348
small updates to the protocol
zadjii-msft Feb 16, 2023
026f342
Merge remote-tracking branch 'origin/dev/migrie/f/3121-wE-dOnT-hAvE-d…
zadjii-msft Feb 21, 2023
ff5eead
Very important that the backspaces are trimmed from the preview
zadjii-msft Feb 21, 2023
2c66c32
bottoms up bottoms up
zadjii-msft Feb 21, 2023
d94183b
icons are _slick_
zadjii-msft Feb 21, 2023
8feb909
bottom-up mode is basically done
zadjii-msft Feb 21, 2023
f5909d9
Open in different directions based on available space
zadjii-msft Feb 22, 2023
4516b4b
Properly account for the position of panes when opening the menu
zadjii-msft Feb 22, 2023
a3c4776
clamp horizontally
zadjii-msft Feb 23, 2023
7988d89
code cleanup
zadjii-msft Feb 23, 2023
84a41b4
cleanup _for review_?
zadjii-msft Feb 23, 2023
36b5759
[PARENT] lmao I deleted the line that sends the inpu :facepalm"
zadjii-msft Feb 24, 2023
f3796da
mostly all the plumbing to get this back into a reasonable state
zadjii-msft Feb 24, 2023
f4c310a
make this actually work again
zadjii-msft Feb 24, 2023
dc71f0c
align to the cursor in bottoms up mode
zadjii-msft Feb 24, 2023
c9e7156
notes, cleanup, order the history correctly
zadjii-msft Feb 24, 2023
5defde5
POC: We can take it out of the Popup and have it still work
zadjii-msft Feb 24, 2023
57a5327
very confident we can get all the logic into the sxnui
zadjii-msft Feb 24, 2023
a172f53
Finish detaching it from the popup
zadjii-msft Mar 1, 2023
e2cc278
POC: We can take it out of the Popup and have it still work
zadjii-msft Feb 24, 2023
e544871
very confident we can get all the logic into the sxnui
zadjii-msft Feb 24, 2023
173a830
Finish detaching it from the popup
zadjii-msft Mar 1, 2023
a21c815
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Mar 1, 2023
20f5651
final cleanup for review
zadjii-msft Mar 1, 2023
236912a
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Mar 2, 2023
84a8dd2
a nugget of where I want to start this
zadjii-msft Mar 2, 2023
442413f
Final cleanup for review
zadjii-msft Mar 2, 2023
9d5ef3a
format and spell
zadjii-msft Mar 2, 2023
cd2db82
Merge branch 'main' into dev/migrie/fhl-2023/pwsh-autocomplete-demo
zadjii-msft Mar 10, 2023
22c94bf
spell
zadjii-msft Mar 10, 2023
28555a6
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2023/p…
zadjii-msft Mar 20, 2023
36b676a
Add a setting to opt in, because feature flags are imprecise
zadjii-msft Mar 20, 2023
b096469
austin mode
zadjii-msft Mar 20, 2023
4e46a63
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Mar 20, 2023
6c778a6
yea no I always run the tests
zadjii-msft Mar 20, 2023
172a298
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Mar 21, 2023
dfd4e27
Add a useCommandline property to the suggestions action
zadjii-msft Mar 21, 2023
0c19591
This fixes a previewing issue, all the way back in the first PR
zadjii-msft Mar 21, 2023
db99537
Pre-filter the commands, and use the typed command to construct the s…
zadjii-msft Mar 21, 2023
363c092
substr takes a count you dingus
zadjii-msft Mar 21, 2023
4766b62
substr takes a count, not an end
zadjii-msft Mar 21, 2023
dea426a
And my command name
zadjii-msft Mar 21, 2023
62fb61d
spell
zadjii-msft Mar 21, 2023
dc4a832
substr takes a count, not an end
zadjii-msft Mar 21, 2023
19c1ed9
This fixes a previewing issue, all the way back in the first PR
zadjii-msft Mar 21, 2023
dd5458c
spell
zadjii-msft Mar 21, 2023
df92394
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Mar 21, 2023
51046c5
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Mar 21, 2023
2088d32
Add a range version of ROW::GetText
lhecker Mar 23, 2023
cc05133
Woops, wrong method
lhecker Mar 23, 2023
11916fd
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2023/p…
zadjii-msft Mar 24, 2023
1c52862
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Mar 24, 2023
837c544
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Mar 24, 2023
3ea3860
this is so much cleaner
zadjii-msft Mar 27, 2023
d593fe1
Add a range version of ROW::GetText
lhecker Mar 23, 2023
f56d258
Woops, wrong method
lhecker Mar 23, 2023
4c2499c
this is so much cleaner
zadjii-msft Mar 27, 2023
057098e
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2023/p…
zadjii-msft Apr 5, 2023
62863f1
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' of https://gi…
zadjii-msft Apr 5, 2023
a530ccc
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Apr 5, 2023
920353a
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Apr 5, 2023
3fc364c
Merge branch 'main' into dev/migrie/fhl-2023/pwsh-autocomplete-demo
zadjii-msft May 31, 2023
fb40b5d
lazy loading for fun and profit
zadjii-msft May 31, 2023
d4422bb
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft May 31, 2023
6575e5a
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft May 31, 2023
c71ba64
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Jul 5, 2023
2cf9f41
Merge branch 'main' into dev/migrie/fhl-2023/pwsh-autocomplete-demo
zadjii-msft Jul 5, 2023
b8d8f11
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Jul 5, 2023
ad62ad8
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Jul 5, 2023
2080b92
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Jul 5, 2023
d3e572d
This needs to go way earlier in the stack of PRs
zadjii-msft Jul 6, 2023
967261d
The whole thing
zadjii-msft Jul 6, 2023
0c39b37
notes
zadjii-msft Jul 6, 2023
ca3f7d4
trim commandlines for tasks
zadjii-msft Jul 6, 2023
1a23198
nested ones get filtered to sendInput new too
zadjii-msft Jul 6, 2023
741b773
This needs to go way earlier in the stack of PRs
zadjii-msft Jul 6, 2023
434572a
Merge branch 'main' into dev/migrie/fhl-2023/pwsh-autocomplete-demo
zadjii-msft Aug 1, 2023
12d2160
minor code movement
zadjii-msft Aug 1, 2023
f10f14c
this is better
zadjii-msft Aug 1, 2023
1a8275e
move code around
zadjii-msft Aug 1, 2023
7ae4716
use less int math where possible
zadjii-msft Aug 1, 2023
1720905
last refactoring - Open() instead of Anchor()
zadjii-msft Aug 2, 2023
45a6e1d
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Aug 2, 2023
8879a1f
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 2, 2023
27b3aac
this needed refactoring
zadjii-msft Aug 2, 2023
73a96ad
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 2, 2023
7c3fd2a
Remove input previewing. We can necro later. It's too hacky
zadjii-msft Aug 2, 2023
3ee1f9b
load bearing I guess
zadjii-msft Aug 2, 2023
ce70a37
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Aug 2, 2023
0bb3a8f
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 2, 2023
f9a764e
lots of load bearing code here
zadjii-msft Aug 2, 2023
a013020
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2023/p…
zadjii-msft Aug 8, 2023
0cf6475
whole pile of PR nits
zadjii-msft Aug 8, 2023
902ee8e
raise the event relative to the sender
zadjii-msft Aug 8, 2023
8f0b6f8
revert 1449088, d3b5533 and 0bda66f, because we didn't know what they…
zadjii-msft Aug 8, 2023
4de9303
runformat
zadjii-msft Aug 8, 2023
873d8d4
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2023/p…
zadjii-msft Aug 8, 2023
a21977b
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Aug 8, 2023
ff5ce00
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 8, 2023
4449109
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 8, 2023
16492a7
fix the build
zadjii-msft Aug 8, 2023
9070557
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 8, 2023
2d54223
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 8, 2023
4cccc2d
more build breaks
zadjii-msft Aug 8, 2023
1759213
oneliner mistakes
zadjii-msft Aug 9, 2023
c1339bc
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Aug 9, 2023
a68f229
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 9, 2023
90238ac
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 9, 2023
ef7f563
this would crash the palette if there were nested items
zadjii-msft Aug 9, 2023
2bceb92
these are also vestigial
zadjii-msft Aug 9, 2023
4110f2c
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Aug 9, 2023
b7f8b36
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 9, 2023
9bacdb1
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 9, 2023
a33af4f
update my formatter so it stops blowing up
zadjii-msft Aug 9, 2023
dff4ae3
update my formatter so it stops blowing up
zadjii-msft Aug 9, 2023
3748900
Merge branch 'dev/migrie/fhl-2023/pwsh-autocomplete-demo' into dev/mi…
zadjii-msft Aug 9, 2023
8767448
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 9, 2023
dd56c4b
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 9, 2023
f23c859
Apply suggestions from code review
zadjii-msft Aug 10, 2023
1e91a1c
Merge remote-tracking branch 'origin/main' into dev/migrie/f/14779-sx…
zadjii-msft Aug 14, 2023
f84d139
remove comment
zadjii-msft Aug 14, 2023
382983e
Merge branch 'dev/migrie/f/14779-sxnui-recent-commands' into dev/migr…
zadjii-msft Aug 14, 2023
2772094
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 14, 2023
d4d635d
update GenerateName to actually work
zadjii-msft Aug 14, 2023
e0d7754
schema, as from spec
zadjii-msft Aug 14, 2023
3be1201
Merge remote-tracking branch 'origin/main' into dev/migrie/f/sxnui-us…
zadjii-msft Aug 15, 2023
54234a9
runformat
zadjii-msft Aug 15, 2023
c9fb788
Merge branch 'dev/migrie/f/sxnui-useCommandline' into dev/migrie/f/15…
zadjii-msft Aug 15, 2023
26c35f9
Merge remote-tracking branch 'origin/main' into dev/migrie/f/1595-tasks
zadjii-msft Aug 15, 2023
a6e80d7
comments from review, including a resw change
zadjii-msft Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@
}
]
},
"BuiltinSuggestionSource": {
"enum": [
"commandHistory",
"tasks",
"all"
],
"type": "string"
},
"SuggestionSource": {
"default": "all",
"description": "Either a single suggestion source, or an array of sources to concatenate. Built-in sources include `commandHistory`, `directoryHistory`, and `tasks`. The special value `all` indicates all suggestion sources should be included",
"$comment": "`tasks` and `local` are sources that would be added by the Tasks feature, as a follow-up",
"oneOf": [
{
"type": [ "string", "null", "BuiltinSuggestionSource" ]
},
{
"type": "array",
"items": { "type": "BuiltinSuggestionSource" }
},
{
"type": "array",
"items": { "type": "string" }
}
]
},
"AppearanceConfig": {
"properties": {
"colorScheme": {
Expand Down Expand Up @@ -398,6 +424,7 @@
"sendInput",
"setColorScheme",
"setTabColor",
"showSuggestions",
"splitPane",
"switchToTab",
"tabSearch",
Expand Down Expand Up @@ -1767,6 +1794,30 @@
}
]
},
"ShowSuggestionsAction": {
"description": "Arguments corresponding to a Open Suggestions Action",
"allOf": [
{
"$ref": "#/$defs/ShortcutAction"
},
{
"properties": {
"action": {
"type": "string",
"const": "showSuggestions"
},
"source": {
"$ref": "#/$defs/SuggestionSource",
"description": "Which suggestion sources to filter."
},
"useCommandline": {
"default": false,
"description": "When set to `true`, the current commandline the user has typed will pre-populate the filter of the Suggestions UI. This requires that the user has enabled shell integration in their shell's config. When set to false, the filter will start empty."
}
}
}
]
},
"ShowCloseButton": {
"enum": [
"always",
Expand Down Expand Up @@ -2037,6 +2088,9 @@
{
"$ref": "#/$defs/SearchWebAction"
},
{
"$ref": "#/$defs/ShowSuggestionsAction"
},
{
"type": "null"
}
Expand Down
63 changes: 50 additions & 13 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,25 +1264,62 @@ namespace winrt::TerminalApp::implementation
{
if (const auto& realArgs = args.ActionArgs().try_as<SuggestionsArgs>())
{
auto source = realArgs.Source();

switch (source)
{
case SuggestionsSource::CommandHistory:
const auto source = realArgs.Source();
std::vector<Command> commandsCollection;
Control::CommandHistoryContext context{ nullptr };
winrt::hstring currentCommandline = L"";

// If the user wanted to use the current commandline to filter results,
// OR they wanted command history (or some other source that
// requires context from the control)
// then get that here.
const bool shouldGetContext = realArgs.UseCommandline() ||
WI_IsFlagSet(source, SuggestionsSource::CommandHistory);
if (shouldGetContext)
{
if (const auto& control{ _GetActiveControl() })
Copy link
Member

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 of active control?

{
const auto context = control.CommandHistory();
const auto& currentCmd{ realArgs.UseCommandline() ? context.CurrentCommandline() : L"" };
_OpenSuggestions(control,
Command::HistoryToCommands(context.History(), currentCmd, false),
SuggestionsMode::Palette,
currentCmd);
context = control.CommandHistory();
if (context)
{
currentCommandline = context.CurrentCommandline();
}
}
args.Handled(true);
}
break;

// Aggregate all the commands from the different sources that
// the user selected.

// Tasks are all the sendInput commands the user has saved in
// their settings file. Ask the ActionMap for those.
if (WI_IsFlagSet(source, SuggestionsSource::Tasks))
{
const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSendInput(currentCommandline);
for (const auto& t : tasks)
{
commandsCollection.push_back(t);
}
}

// Command History comes from the commands in the buffer,
// assuming the user has enabled shell integration. Get those
// from the active control.
if (WI_IsFlagSet(source, SuggestionsSource::CommandHistory) &&
context != nullptr)
{
const auto recentCommands = Command::HistoryToCommands(context.History(), currentCommandline, false);
for (const auto& t : recentCommands)
{
commandsCollection.push_back(t);
}
}

// Open the palette with all these commands in it.
_OpenSuggestions(_GetActiveControl(),
winrt::single_threaded_vector<Command>(std::move(commandsCollection)),
SuggestionsMode::Palette,
currentCommandline);
args.Handled(true);
}
}
}
Expand Down
37 changes: 28 additions & 9 deletions src/cascadia/TerminalSettingsModel/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: std::wstring_view{ RS_(L"SuggestionsCommandKey") }.
You can also just use std::wstring::append() instead of using wstringsteam, because string streams are fairly hefty.

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
9 changes: 6 additions & 3 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ namespace Microsoft.Terminal.Settings.Model
ToCurrent,
ToMouse,
};

[flags]
enum SuggestionsSource
{
Tasks,
CommandHistory,
DirectoryHistory,
Tasks = 0x1,
CommandHistory = 0x2,
DirectoryHistory = 0x4,
All = 0xffffffff,
};

[default_interface] runtimeclass NewTerminalArgs {
Expand Down
68 changes: 68 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,4 +931,72 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
return _ExpandedCommandsCache;
}

IVector<Model::Command> _filterToSendInput(IMapView<hstring, Model::Command> nameMap,
Copy link
Member

Choose a reason for hiding this comment

The 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"")) });
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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...

Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void ExpandCommands(const Windows::Foundation::Collections::IVectorView<Model::Profile>& profiles,
const Windows::Foundation::Collections::IMapView<winrt::hstring, Model::ColorScheme>& schemes);

winrt::Windows::Foundation::Collections::IVector<Model::Command> FilterToSendInput(winrt::hstring currentCommandline);

private:
std::optional<Model::Command> _GetActionByID(const InternalActionID actionID) const;
std::optional<Model::Command> _GetActionByKeyChordInternal(const Control::KeyChord& keys) const;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionMap.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Microsoft.Terminal.Settings.Model
Windows.Foundation.Collections.IMapView<Microsoft.Terminal.Control.KeyChord, Command> GlobalHotkeys { get; };

IVector<Command> ExpandedCommands { get; };

IVector<Command> FilterToSendInput(String CurrentCommandline);
};

[default_interface] runtimeclass ActionMap : IActionMapView
Expand Down
13 changes: 12 additions & 1 deletion src/cascadia/TerminalSettingsModel/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot to mark this one for the std::vector vs. IVector thing

}

// Function Description:
// - reports if the current command has nested commands
// - This CANNOT detect { "name": "foo", "commands": null }
Expand Down Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
bool HasNestedCommands() const;
bool IsNestedCommand() const noexcept;
Windows::Foundation::Collections::IMapView<winrt::hstring, Model::Command> NestedCommands() const;
void NestedCommands(const Windows::Foundation::Collections::IVectorView<Model::Command>& nested);

bool HasName() const noexcept;
hstring Name() const noexcept;
Expand Down
Loading
Loading