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 actions in fragments #16185

Merged
merged 7 commits into from
Feb 26, 2024
Merged

Conversation

zadjii-msft
Copy link
Member

Surprisingly easier than I thought this would be. ActionMap already supports layering (from defaults.json), so this basically re-uses a lot of that for fun and profit.

The trickiest bits:

  • In SettingsLoader::_parseFragment, I'm constructing a fake, empty JSON object, and taking only the actions out from the fragment, and stuffing them into this temp json. Then, I parse that as a globals object, and set that as the parent to the user settings file. That results in only the actions from the fragment being parsed before the user's actions.
  • In that same method, I'm also explicitly preventing the ActionMap (et al.) from parsing keys from these actions. We don't want fragments to be able to say "ctrl+f is clear buffer" or something like that. This required a bit of annoying plumbing.

Closes #16063
Tests added.
Docs need to be updated.

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal. labels Oct 17, 2023
@github-actions

This comment has been minimized.

// Add the parsed fragment globals as a parent of the user's settings.
// Later, in FinalizeInheritance, this will result in the action map from
// the fragments being applied before the user's own settings.
userSettings.globals->AddLeastImportantParent(settings.globals);
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite get this change and how it replaces the previous code.

Copy link
Member Author

Choose a reason for hiding this comment

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

So this one was tricky - it would manually insert schemes from fragments into the userSettings, which was weird but okay. Now, instead of doing that, I just set the whole globals object to be a parent of the user's globals. We'll still resolve the schemes in a similar way in GlobalAppSettings::_FinalizeInheritance, but we'll also do the right thing for actions now too.

Copy link
Member

Choose a reason for hiding this comment

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

ah, this is likely to have downstream effects on me as well. thanks!

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

  • Do we want to prevent the fragment from adding global actions like "globalSummon"?

@zadjii-msft
Copy link
Member Author

  • Do we want to prevent the fragment from adding global actions like "globalSummon"?

meh? They won't be able to add a key for it, so I don't think it'll actually be able to do anything. I suppose an app can just add one that we'll store but ultimately won't be useful.

VERIFY_IS_TRUE(nested.HasNestedCommands());
VERIFY_ARE_EQUAL(settings->GlobalSettings().ColorSchemes().Size(), nested.NestedCommands().Size());
}
void DeserializationTests::FragmentActionRoundtrip()
Copy link
Member

Choose a reason for hiding this comment

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

i like the round-trip test verifying we didn't serialize someone else's action. clever.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

honestly, i am not seeing a fake empty JSON object. can you point it out? or update the description if it is wrong

@zadjii-msft zadjii-msft merged commit 88def9d into main Feb 26, 2024
17 checks passed
@zadjii-msft zadjii-msft deleted the dev/migrie/f/fragment-actions branch February 26, 2024 20:27
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fragments should be able to add actions
4 participants