Compare commits

...

111 Commits

Author SHA1 Message Date
Mike Griese
deab3fe05b Merge remote-tracking branch 'origin/main' into dev/migrie/f/local-snippets-cleaner 2024-06-07 05:24:14 -05:00
Mike Griese
eb750cca26 Merge remote-tracking branch 'origin/dev/pabhoj/action_new_tab_menu' into dev/migrie/f/local-snippets-cleaner 2024-06-07 05:21:24 -05:00
Pankaj Bhojwani
ab65ecbb39 Merge branch 'dev/pabhoj/command_keys' into dev/pabhoj/action_new_tab_menu 2024-06-04 13:06:42 -07:00
Pankaj Bhojwani
cc837b6e5d fix test 2024-06-04 13:05:53 -07:00
Pankaj Bhojwani
0f7e9f331b fixes 2024-06-04 12:50:15 -07:00
Pankaj Bhojwani
589a1e0f96 IDTo 2024-06-04 11:29:23 -07:00
Pankaj Bhojwani
6ea25e4381 ID 2024-06-04 11:24:24 -07:00
Pankaj Bhojwani
258c6eb1f8 O(1), rename maps for clarity 2024-06-04 11:19:49 -07:00
Pankaj Bhojwani
327858b2af Merge branch 'dev/pabhoj/action_refactor' into dev/pabhoj/command_keys 2024-06-04 10:20:27 -07:00
Pankaj Bhojwani
96d8d1f8ea Merge branch 'main' of https://github.com/microsoft/terminal into dev/pabhoj/action_refactor 2024-06-04 10:19:47 -07:00
Pankaj Bhojwani
5a00d5f400 nits and changes 2024-06-03 16:13:37 -07:00
Pankaj Bhojwani
253dedf477 conflict 2024-06-03 11:31:47 -07:00
Mike Griese
f0bc7f1a28 last cleanup before review 2024-06-01 21:42:03 -05:00
Mike Griese
3aa5b4bb29 more cleanup 2024-06-01 21:33:04 -05:00
Mike Griese
091797c08b cleanup 2024-06-01 21:33:00 -05:00
Mike Griese
d41e9735af a much cleaner abstraction 2024-06-01 21:32:54 -05:00
Mike Griese
5a029f0744 smaller refactors 2024-06-01 21:32:48 -05:00
Mike Griese
bba8aac96d use a cache in actionmap to stash commands as we parse them 2024-06-01 21:32:39 -05:00
Mike Griese
5466965d4f Actually works in suggestions UI again 2024-06-01 21:32:14 -05:00
Mike Griese
b5d063b48e plumb it through. It works
(cherry-picked from 38999195b)
2024-06-01 21:31:20 -05:00
Pankaj Bhojwani
406312f2f8 fix loops 2024-05-31 19:33:07 -07:00
Pankaj Bhojwani
625753cc41 x86 hash 2024-05-31 17:52:20 -07:00
Pankaj Bhojwani
a80316dfa5 1 more test 2024-05-31 16:56:34 -07:00
Pankaj Bhojwani
9703815f59 nits n fixes 2024-05-31 16:32:21 -07:00
Pankaj Bhojwani
0dff336556 nits, schema 2024-05-31 10:51:36 -07:00
Pankaj Bhojwani
b88a8c5884 eraseif 2024-05-30 13:03:03 -07:00
Pankaj Bhojwani
6c6dd46e02 leonard comments 2024-05-20 15:06:31 -07:00
Pankaj Bhojwani
51528e9cfd spaces 2024-05-16 16:59:35 -07:00
Pankaj Bhojwani
40b4aa2c94 works 2024-05-16 16:50:56 -07:00
Pankaj Bhojwani
d4d216ca33 don't need helper anymore 2024-05-08 10:48:33 -07:00
Pankaj Bhojwani
7d00b25fbf spelling 2024-05-08 10:11:16 -07:00
Pankaj Bhojwani
ba375ec2a2 remove keys from command 2024-05-08 10:00:45 -07:00
Pankaj Bhojwani
5e48a45ba2 update add action 2024-05-07 15:56:52 -07:00
Pankaj Bhojwani
14d83b5f5c delete user actions that are identical to inbox actions 2024-05-06 16:50:01 -07:00
Pankaj Bhojwani
3e31bda6f2 generate here instead 2024-05-06 15:29:24 -07:00
Pankaj Bhojwani
4d35c14966 schema conflict 2024-05-03 14:54:09 -07:00
Pankaj Bhojwani
abef25d29c move this to header 2024-05-03 14:51:51 -07:00
Pankaj Bhojwani
7793c5c5bc schema 2024-05-03 13:30:09 -07:00
Pankaj Bhojwani
ccf1cc9e83 nits 2024-05-02 19:06:51 -07:00
Pankaj Bhojwani
ebc03e98f4 another test 2024-05-02 18:44:44 -07:00
Pankaj Bhojwani
80fc299c10 some new tests 2024-05-02 18:11:46 -07:00
Pankaj Bhojwani
02a1e37aae correct GH todo 2024-05-01 18:05:06 -07:00
Pankaj Bhojwani
0480d651cb this is better 2024-05-01 17:54:46 -07:00
Pankaj Bhojwani
193e5733bf fix remaining tests 2024-05-01 17:36:31 -07:00
Pankaj Bhojwani
2b16acd4cf check for name, fix some tests 2024-05-01 14:48:37 -07:00
Pankaj Bhojwani
f35bf206e6 Merge branch 'main' of https://github.com/microsoft/terminal into dev/pabhoj/action_refactor 2024-05-01 10:50:02 -07:00
Pankaj Bhojwani
cdb907d94d mark todo 2024-04-30 17:43:25 -07:00
Pankaj Bhojwani
3e601f5b66 better if 2024-04-30 17:36:37 -07:00
Pankaj Bhojwani
c2c75c80ed bandaid temporary fix for name 2024-04-30 17:33:53 -07:00
Pankaj Bhojwani
3c6015d97b remove _getcumulativeactions 2024-04-30 16:45:59 -07:00
Pankaj Bhojwani
45cfcd6eca just add duplicate pane auto to defaults 2024-04-30 15:24:33 -07:00
Pankaj Bhojwani
ca4015f5f9 only one tojson 2024-04-30 15:19:33 -07:00
Pankaj Bhojwani
4c744e6ab3 misc 2024-04-30 14:56:42 -07:00
Pankaj Bhojwani
6437b9f508 fix user defaults file 2024-04-30 14:36:09 -07:00
Pankaj Bhojwani
428821b40c remove _idwasgenerated 2024-04-30 13:04:14 -07:00
Pankaj Bhojwani
3d92f27de7 format 2024-04-30 11:18:12 -07:00
Pankaj Bhojwani
db00b90306 spelling things 2024-04-30 11:14:21 -07:00
Pankaj Bhojwani
e725f1e936 resolve conflict 2024-04-30 11:09:51 -07:00
Pankaj Bhojwani
e62dfa2177 some comments 2024-04-30 11:09:15 -07:00
Pankaj Bhojwani
2b4aeb2b11 don't check for special in standard 2024-04-30 11:04:01 -07:00
Pankaj Bhojwani
2f1d8d2dca update defaults 2024-04-30 10:34:58 -07:00
Pankaj Bhojwani
754bf04ab3 mark gh todo 2024-04-30 10:27:25 -07:00
Pankaj Bhojwani
c51558ff4c unmark these 2024-04-30 10:20:07 -07:00
Pankaj Bhojwani
5a1b822833 reimplement populating all known keybindings 2024-04-29 21:33:33 -07:00
Pankaj Bhojwani
b3e9c267f5 remove check for invalid 2024-04-27 16:22:14 -07:00
Pankaj Bhojwani
936afd6b01 _getactionbyid no longer returns optional 2024-04-27 16:16:25 -07:00
Pankaj Bhojwani
dc874c3b3f rename to special/standard 2024-04-27 15:36:17 -07:00
Pankaj Bhojwani
ae16a5e0e1 started stage 3 2024-04-26 15:43:06 -07:00
Pankaj Bhojwani
3e7ab3861a sui works? 2024-04-26 11:26:10 -07:00
Pankaj Bhojwani
ddfac907f4 Merge branch 'main' of https://github.com/microsoft/terminal into dev/pabhoj/action_refactor 2024-04-26 09:56:46 -07:00
Pankaj Bhojwani
f1633e0360 overwritten IDs and overwritten keychords show up properly in the SUI 2024-04-25 21:25:17 -07:00
Pankaj Bhojwani
12a61c595e shows up in sui and all keybindings work 2024-04-25 19:16:27 -07:00
Pankaj Bhojwani
d0938e2a24 ugly way to make sure we fixup 2024-04-24 18:15:37 -07:00
Pankaj Bhojwani
f425746169 remove keysmap 2024-04-24 16:21:22 -07:00
Pankaj Bhojwani
e28d47888c some todos for later 2024-04-24 16:04:39 -07:00
Pankaj Bhojwani
0a3e17eebb edge cases 2024-04-24 15:33:35 -07:00
Pankaj Bhojwani
22ab9363ef works?? 2024-04-24 14:33:01 -07:00
Pankaj Bhojwani
c134402507 about to test stage 1 2024-04-24 11:24:40 -07:00
Pankaj Bhojwani
85933e2231 midpoint 2024-04-23 09:49:27 -07:00
Pankaj Bhojwani
ca3eb87301 rename and comment 2024-04-17 16:58:04 -07:00
Pankaj Bhojwani
5e70911a68 remove 0 2024-04-17 16:49:58 -07:00
Pankaj Bhojwani
360b92e567 fmt_compile, fix test 2024-04-17 16:38:52 -07:00
Pankaj Bhojwani
5ee630ec82 fmt is smart 2024-04-12 15:16:36 -07:00
Pankaj Bhojwani
aa4921268e null check 2024-04-12 15:08:53 -07:00
Pankaj Bhojwani
12f3aa9d06 truncate and hex, debug assert 2024-04-12 15:04:23 -07:00
Pankaj Bhojwani
bdf42c2d9c first round of nits 2024-04-11 16:05:35 -07:00
Pankaj Bhojwani
af2d22f343 defaults conflict 2024-04-11 09:42:42 -07:00
Pankaj Bhojwani
6e293a5ee8 Everytime 2024-04-01 10:26:54 -07:00
Pankaj Bhojwani
dd25ed762f change tests 2024-04-01 10:23:23 -07:00
Pankaj Bhojwani
dca7df50c8 excess line 2024-03-29 13:49:33 -07:00
Pankaj Bhojwani
9fc69721c9 add tests 2024-03-29 13:40:53 -07:00
Pankaj Bhojwani
5c2307c531 fix test 2024-03-28 11:48:51 -07:00
Pankaj Bhojwani
d57c7a1f03 move this 2024-03-27 18:04:12 -07:00
Pankaj Bhojwani
71bf90f295 even better, also get the ID from json 2024-03-27 18:02:17 -07:00
Pankaj Bhojwani
10d1fc8d60 this way is better 2024-03-27 17:30:55 -07:00
Pankaj Bhojwani
44510dce1b move id generation to fixupusersettings 2024-03-27 17:14:21 -07:00
Pankaj Bhojwani
eccd87f303 update comment 2024-03-27 15:38:50 -07:00
Pankaj Bhojwani
6c3253968f string of numbers is unsightly but it works 2024-03-27 15:37:19 -07:00
Pankaj Bhojwani
2093660ac1 line 2024-03-26 11:45:44 -07:00
Pankaj Bhojwani
b43191d2c5 spacing 2024-03-26 11:44:47 -07:00
Pankaj Bhojwani
7c907fed6e nits 2024-03-26 11:43:50 -07:00
Pankaj Bhojwani
db528c94fc generate IDs for user commands 2024-03-26 11:29:12 -07:00
Pankaj Bhojwani
be193b21eb merge origin 2024-03-19 15:08:08 -07:00
Pankaj Bhojwani
2bb1b6c6ad conflict 2024-03-19 12:18:06 -07:00
Pankaj Bhojwani
66fe08f964 default ids 2024-03-06 17:24:39 -08:00
Pankaj Bhojwani
642d0ab2b7 inbox makes more sense 2024-03-05 15:47:49 -08:00
Pankaj Bhojwani
8cc82de489 generated 2024-03-05 15:42:38 -08:00
Pankaj Bhojwani
052d063686 ah one of the tests uses this 2024-03-05 14:36:45 -08:00
Pankaj Bhojwani
8bcbd0bd42 fix tests 2024-03-05 14:20:14 -08:00
Pankaj Bhojwani
9dff28f23d update calls in tests 2024-03-05 13:51:18 -08:00
Pankaj Bhojwani
90627b3ae5 add origin tag 2024-03-05 11:35:26 -08:00
15 changed files with 229 additions and 70 deletions

28
.wt.json Normal file
View File

@@ -0,0 +1,28 @@
{
"actions":
[
{
"command": { "action": "sendInput", "input": "bx\r" },
"name": "Build project",
"description": "Build the project in the CWD"
},
{
"command": { "action": "sendInput", "input": "bz\r" },
"name": "Build solution, incremental",
"description": "Just build changes to the solution"
},
{
"command": { "action": "sendInput", "input": "bcz\r" },
"name": "Clean & build solution",
"icon": "\uE8e6",
"description": "Start over. Go get your coffee. "
},
{
"command": { "action": "sendInput", "input": "nuget push -apikey az -source TerminalDependencies %userprofile%\\Downloads" },
"name": "Upload package to nuget feed",
"icon": "\uE898",
"description": "Go download a .nupkg, put it in ~/Downloads, and use this to push to our private feed."
},
]
}

View File

@@ -1330,66 +1330,77 @@ namespace winrt::TerminalApp::implementation
{
if (const auto& realArgs = args.ActionArgs().try_as<SuggestionsArgs>())
{
const auto source = realArgs.Source();
std::vector<Command> commandsCollection;
Control::CommandHistoryContext context{ nullptr };
winrt::hstring currentCommandline = L"";
_doHandleSuggestions(realArgs);
// 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() })
{
context = control.CommandHistory();
if (context)
{
currentCommandline = context.CurrentCommandline();
}
}
}
// 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);
}
}
}
winrt::fire_and_forget TerminalPage::_doHandleSuggestions(SuggestionsArgs realArgs)
{
const auto source = realArgs.Source();
std::vector<Command> commandsCollection;
Control::CommandHistoryContext context{ nullptr };
winrt::hstring currentCommandline = L"";
winrt::hstring currentWorkingDirectory = 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_IsAnyFlagSet(source, SuggestionsSource::CommandHistory);
if (const auto& control{ _GetActiveControl() })
{
currentWorkingDirectory = control.CurrentWorkingDirectory();
if (shouldGetContext)
{
context = control.CommandHistory();
if (context)
{
currentCommandline = context.CurrentCommandline();
}
}
}
// 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 = co_await _settings.GlobalSettings().ActionMap().FilterToSnippets(currentCommandline, currentWorkingDirectory);
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);
}
}
co_await wil::resume_foreground(Dispatcher());
// Open the palette with all these commands in it.
_OpenSuggestions(_GetActiveControl(),
winrt::single_threaded_vector<Command>(std::move(commandsCollection)),
SuggestionsMode::Palette,
currentCommandline);
}
void TerminalPage::_HandleColorSelection(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{

View File

@@ -544,6 +544,7 @@ namespace winrt::TerminalApp::implementation
winrt::com_ptr<TerminalTab> _senderOrFocusedTab(const IInspectable& sender);
void _activePaneChanged(winrt::TerminalApp::TerminalTab tab, Windows::Foundation::IInspectable args);
winrt::fire_and_forget _doHandleSuggestions(Microsoft::Terminal::Settings::Model::SuggestionsArgs realArgs);
#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp

View File

@@ -2246,7 +2246,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
std::vector<winrt::hstring> commands;
const auto bufferCommands{ textBuffer.Commands() };
auto trimToHstring = [](const auto& s) -> winrt::hstring {
const auto strEnd = s.find_last_not_of(UNICODE_SPACE);
if (strEnd != std::string::npos)
@@ -2282,6 +2282,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return *context;
}
winrt::hstring ControlCore::CurrentWorkingDirectory() const
{
return winrt::hstring{ _terminal->GetWorkingDirectory() };
}
Core::Scheme ControlCore::ColorScheme() const noexcept
{
Core::Scheme s;

View File

@@ -184,6 +184,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ContextMenuSelectCommand();
void ContextMenuSelectOutput();
winrt::hstring CurrentWorkingDirectory() const;
#pragma endregion
#pragma region ITerminalInput

View File

@@ -62,5 +62,7 @@ namespace Microsoft.Terminal.Control
void SelectOutput(Boolean goUp);
IVector<ScrollMark> ScrollMarks { get; };
String CurrentWorkingDirectory { get; };
};
}

View File

@@ -3558,6 +3558,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return _core.CommandHistory();
}
winrt::hstring TermControl::CurrentWorkingDirectory() const
{
return _core.CurrentWorkingDirectory();
}
Core::Scheme TermControl::ColorScheme() const noexcept
{

View File

@@ -113,6 +113,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void SelectCommand(const bool goUp);
void SelectOutput(const bool goUp);
winrt::hstring CurrentWorkingDirectory() const;
#pragma endregion
void ScrollViewport(int viewTop);

View File

@@ -805,10 +805,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return _ExpandedCommandsCache;
}
IVector<Model::Command> _filterToSendInput(IMapView<hstring, Model::Command> nameMap,
winrt::hstring currentCommandline)
#pragma region Snippets
std::vector<Model::Command> _filterToSnippets(IMapView<hstring, Model::Command> nameMap,
winrt::hstring currentCommandline,
const std::vector<Model::Command>& localCommands)
{
auto results = winrt::single_threaded_vector<Model::Command>();
std::vector<Model::Command> results{};
const auto numBackspaces = currentCommandline.size();
// Helper to clone a sendInput command into a new Command, with the
@@ -847,21 +849,22 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return *copy;
};
// iterate over all the commands in all our actions...
for (auto&& [name, command] : nameMap)
{
// Helper to copy this command into a snippet-styled command, and any
// nested commands
const auto addCommand = [&](auto& command) {
// 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));
results.push_back(createInputAction(command));
}
// If this is nested...
else if (command.HasNestedCommands())
{
// Look for any sendInput commands nested underneath us
auto innerResults = _filterToSendInput(command.NestedCommands(), currentCommandline);
std::vector<Model::Command> empty{};
auto innerResults = winrt::single_threaded_vector<Model::Command>(std::move(_filterToSnippets(command.NestedCommands(), currentCommandline, empty)));
if (innerResults.Size() > 0)
{
@@ -874,17 +877,98 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
auto copy = cmdImpl->Copy();
copy->NestedCommands(innerResults.GetView());
results.Append(*copy);
results.push_back(*copy);
}
}
};
// iterate over all the commands in all our actions...
for (auto&& [name, command] : nameMap)
{
addCommand(command);
}
// ... and all the local commands passed in here
for (const auto& command : localCommands)
{
addCommand(command);
}
return results;
}
IVector<Model::Command> ActionMap::FilterToSendInput(
winrt::hstring currentCommandline)
// Update ActionMap's cache of actions for this directory. We'll look for a
// .wt.json in this directory. If it exists, we'll read it, parse it's JSON,
// then take all the sendInput actions in it and store them in our
// _cwdLocalSnippetsCache
winrt::Windows::Foundation::IAsyncAction ActionMap::_updateLocalSnippetCache(winrt::hstring currentWorkingDirectory)
{
return _filterToSendInput(NameMap(), currentCommandline);
// Don't do I/O on the main thread, duh
co_await winrt::resume_background();
// This returns an empty string if we fail to load the file.
auto localTasksFileContents = CascadiaSettings::ReadFile(currentWorkingDirectory + L"\\.wt.json");
if (!localTasksFileContents.empty())
{
auto data = winrt::to_string(localTasksFileContents);
std::string errs;
static std::unique_ptr<Json::CharReader> reader{ Json::CharReaderBuilder::CharReaderBuilder().newCharReader() };
Json::Value root;
if (!reader->parse(data.data(), data.data() + data.size(), &root, &errs))
{
// In the real settings parser, we'd throw here:
// throw winrt::hresult_error(WEB_E_INVALID_JSON_STRING, winrt::to_hstring(errs));
//
// That seems overly agressive for something that we don't
// really own. Instead, just bail out.
co_return;
}
auto result = std::vector<Model::Command>();
if (auto actions{ root[JsonKey("actions")] })
{
std::vector<SettingsLoadWarnings> warnings;
for (const auto& json : actions)
{
auto parsed = Command::FromJson(json, warnings, OriginTag::Generated);
// Skip over things that aren't snippets
if (parsed->ActionAndArgs().Action() != ShortcutAction::SendInput)
{
continue;
}
result.push_back(*parsed);
}
}
_cwdLocalSnippetsCache.insert_or_assign(currentWorkingDirectory, result);
}
// Now at the bottom, we've either found a file successfully parsed it,
// and updated the _cwdLocalSnippetsCache. Or we failed at some point,
// and then it doesn't really matter.
co_return;
}
winrt::Windows::Foundation::IAsyncOperation<IVector<Model::Command>> ActionMap::FilterToSnippets(
winrt::hstring currentCommandline,
winrt::hstring currentWorkingDirectory)
{
// Check if there are any cached commands in this directory.
// If there aren't, then we'll try to look for any commands in this
// dir's .wt.json
auto cachedCwdCommands = _cwdLocalSnippetsCache.find(currentWorkingDirectory);
if (cachedCwdCommands == _cwdLocalSnippetsCache.end())
{
// Here, we haven't cached this path yet
co_await _updateLocalSnippetCache(currentWorkingDirectory);
cachedCwdCommands = _cwdLocalSnippetsCache.find(currentWorkingDirectory);
}
auto cachedCommands = cachedCwdCommands != _cwdLocalSnippetsCache.end() ?
cachedCwdCommands->second :
std::vector<Model::Command>{};
co_return winrt::single_threaded_vector<Model::Command>(_filterToSnippets(NameMap(), currentCommandline, cachedCommands));
}
#pragma endregion
}

View File

@@ -83,7 +83,7 @@ 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);
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Foundation::Collections::IVector<Model::Command>> FilterToSnippets(winrt::hstring currentCommandline, winrt::hstring currentWorkingDirectory);
private:
Model::Command _GetActionByID(const winrt::hstring& actionID) const;
@@ -101,6 +101,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void _TryUpdateActionMap(const Model::Command& cmd);
void _TryUpdateKeyChord(const Model::Command& cmd, const Control::KeyChord& keys);
winrt::Windows::Foundation::IAsyncAction _updateLocalSnippetCache(winrt::hstring currentWorkingDirectory);
Windows::Foundation::Collections::IMap<hstring, Model::ActionAndArgs> _AvailableActionsCache{ nullptr };
Windows::Foundation::Collections::IMap<hstring, Model::Command> _NameMapCache{ nullptr };
Windows::Foundation::Collections::IMap<Control::KeyChord, Model::Command> _GlobalHotkeysCache{ nullptr };
@@ -133,6 +135,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// we can give the SUI a view of the key chords and the commands they map to
Windows::Foundation::Collections::IMap<Control::KeyChord, Model::Command> _ResolvedKeyToActionMapCache{ nullptr };
std::unordered_map<hstring, std::vector<Model::Command>> _cwdLocalSnippetsCache{};
friend class SettingsModelUnitTests::KeyBindingsTests;
friend class SettingsModelUnitTests::DeserializationTests;
friend class SettingsModelUnitTests::TerminalSettingsTests;

View File

@@ -22,7 +22,7 @@ namespace Microsoft.Terminal.Settings.Model
IVector<Command> ExpandedCommands { get; };
IVector<Command> FilterToSendInput(String CurrentCommandline);
Windows.Foundation.IAsyncOperation<IVector<Command> > FilterToSnippets(String CurrentCommandline, String CurrentWorkingDirectory);
};
[default_interface] runtimeclass ActionMap : IActionMapView

View File

@@ -1095,6 +1095,20 @@ void CascadiaSettings::ExportFile(winrt::hstring path, winrt::hstring content)
}
CATCH_LOG();
}
winrt::hstring CascadiaSettings::ReadFile(winrt::hstring path)
{
try
{
auto maybeContents = ReadUTF8FileIfExists({ path.c_str() });
if (maybeContents.has_value())
{
return winrt::hstring{ til::u8u16(*maybeContents) };
}
}
CATCH_LOG();
return L"";
}
void CascadiaSettings::_validateThemeExists()
{

View File

@@ -113,6 +113,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static winrt::hstring ApplicationVersion();
static bool IsPortableMode();
static void ExportFile(winrt::hstring path, winrt::hstring content);
static winrt::hstring ReadFile(winrt::hstring path);
CascadiaSettings() noexcept = default;
CascadiaSettings(const winrt::hstring& userJSON, const winrt::hstring& inboxJSON);

View File

@@ -21,6 +21,7 @@ namespace Microsoft.Terminal.Settings.Model
static String ApplicationVersion { get; };
static void ExportFile(String path, String content);
static String ReadFile(String path);
CascadiaSettings(String userJSON, String inboxJSON);

View File

@@ -501,9 +501,10 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FindMatchDirecti
JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SuggestionsSource)
{
static constexpr std::array<pair_type, 5> mappings = {
static constexpr std::array<pair_type, 6> mappings = {
pair_type{ "none", AllClear },
pair_type{ "tasks", ValueType::Tasks },
pair_type{ "snippets", ValueType::Tasks },
pair_type{ "commandHistory", ValueType::CommandHistory },
pair_type{ "directoryHistory", ValueType::DirectoryHistory },
pair_type{ "all", AllSet },