Compare commits

...

1 Commits

Author SHA1 Message Date
Mike Griese
941ef48cfe Add support for disabling nesting in the sinppets menu
Adds a `nesting` param to `showSuggestions`. The default remains `"enabled"`. We now also accept `"disabled"`, which will plop all the snippets into a single top-level list. This will make it easier for users to open suggestions based on what they've already typed at the commandline. e.g. type `gitco` at the commandline, and have that pre-filtered to the `git commit -m ""\u001b[D` snippet.

As spec'd in [Suggestions-UI.md](https://github.com/microsoft/terminal/blob/main/doc/specs/%231595%20-%20Suggestions%20UI/Suggestions-UI.md)
2024-06-10 14:01:30 -05:00
7 changed files with 46 additions and 18 deletions

View File

@@ -1360,7 +1360,7 @@ namespace winrt::TerminalApp::implementation
// their settings file. Ask the ActionMap for those.
if (WI_IsFlagSet(source, SuggestionsSource::Tasks))
{
const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSendInput(currentCommandline);
const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSendInput(currentCommandline, realArgs.Nesting());
for (const auto& t : tasks)
{
commandsCollection.push_back(t);

View File

@@ -216,8 +216,9 @@ protected: \
X(CommandPaletteLaunchMode, LaunchMode, "launchMode", false, CommandPaletteLaunchMode::Action)
////////////////////////////////////////////////////////////////////////////////
#define SUGGESTIONS_ARGS(X) \
X(SuggestionsSource, Source, "source", false, SuggestionsSource::Tasks) \
#define SUGGESTIONS_ARGS(X) \
X(SuggestionsSource, Source, "source", false, SuggestionsSource::Tasks) \
X(SuggestionsNesting, Nesting, "nesting", false, SuggestionsNesting::Enabled) \
X(bool, UseCommandline, "useCommandline", false, false)
////////////////////////////////////////////////////////////////////////////////

View File

@@ -122,6 +122,12 @@ namespace Microsoft.Terminal.Settings.Model
All = 0xffffffff,
};
enum SuggestionsNesting
{
Disabled,
Enabled,
};
interface INewContentArgs {
String Type { get; };
Boolean Equals(INewContentArgs other);
@@ -343,8 +349,9 @@ namespace Microsoft.Terminal.Settings.Model
[default_interface] runtimeclass SuggestionsArgs : IActionArgs
{
SuggestionsArgs();
SuggestionsArgs(SuggestionsSource source, Boolean useCommandline);
SuggestionsArgs(SuggestionsSource source, SuggestionsNesting nesting, Boolean useCommandline);
SuggestionsSource Source { get; };
SuggestionsNesting Nesting { get; };
Boolean UseCommandline { get; };
};

View File

@@ -806,7 +806,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
IVector<Model::Command> _filterToSendInput(IMapView<hstring, Model::Command> nameMap,
winrt::hstring currentCommandline)
winrt::hstring currentCommandline,
Model::SuggestionsNesting nesting)
{
auto results = winrt::single_threaded_vector<Model::Command>();
@@ -861,20 +862,30 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
else if (command.HasNestedCommands())
{
// Look for any sendInput commands nested underneath us
auto innerResults = _filterToSendInput(command.NestedCommands(), currentCommandline);
auto innerResults = _filterToSendInput(command.NestedCommands(), currentCommandline, nesting);
if (innerResults.Size() > 0)
{
// This command did have at least one sendInput under it
if (nesting == Model::SuggestionsNesting::Enabled)
{
// 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());
// 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);
results.Append(*copy);
}
else if (nesting == Model::SuggestionsNesting::Disabled)
{
// Just add all the nested commands directly to the list we're going to return
for (const auto& nested : innerResults)
{
results.Append(nested);
}
}
}
}
}
@@ -883,8 +894,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
IVector<Model::Command> ActionMap::FilterToSendInput(
winrt::hstring currentCommandline)
winrt::hstring currentCommandline,
Model::SuggestionsNesting nesting)
{
return _filterToSendInput(NameMap(), currentCommandline);
return _filterToSendInput(NameMap(), currentCommandline, nesting);
}
}

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::Collections::IVector<Model::Command> FilterToSendInput(winrt::hstring currentCommandline, Model::SuggestionsNesting nesting);
private:
Model::Command _GetActionByID(const winrt::hstring& actionID) const;

View File

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

View File

@@ -510,6 +510,14 @@ JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SuggestionsSourc
};
};
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SuggestionsNesting)
{
JSON_MAPPINGS(2) = {
pair_type{ "enabled", ValueType::Enabled },
pair_type{ "disabled", ValueType::Disabled },
};
};
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::WindowingMode)
{
JSON_MAPPINGS(3) = {