-
Notifications
You must be signed in to change notification settings - Fork 559
Add label for transaction commits for undo/redo grouping. #25938
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
base: main
Are you sure you want to change the base?
Conversation
|
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output |
noencke
left a comment
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.
This is the first half of the feature - adding and setting the property. The second half is to pass the property to the changed and commitApplied event. I think that both halves are small enough changes that you should do them in the same PR. So next:
- Create a
CommitMetadataAlphathat extendsCommitMetadataand has alabel: unknownproperty. - Update both
TreeBranch.commitAppliedandTreeBranch.changedto useCommitMetadataAlpha. - Update the tests to consume the label from the event commit metadata rather than directly from the static.
| * This value is intended to be read within event handlers like `commitApplied`. | ||
| * This value is cleared after each transaction to prevent providing stale/incorrect labels. | ||
| */ | ||
| private static _currentTransactionLabel: unknown | undefined; |
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.
Currently, there is no benefit to having a private property here and then making a getter and setter, because the getter and setter do no validation or transformation of the value.
I do think we would benefit from constraining the way that this field can be set. How about this:
private static transactionLabel?: unknown;
public static runWithTransactionLabel<T>(label: T, fn: (label: T) => void): void {
this.transactionLabel = label;
try {
fn(label);
} finally {
this.transactionLabel = undefined;
}
}Then it's impossible for any code to ever accidentally set the label and forget to clear it, or forget to properly handle errors.
The passing of label to the fn and the resulting generic parameter is not strictly necessary but just a nice to have, IMO.
| * This value is intended to be read within event handlers like `commitApplied`. | ||
| * This value is cleared after each transaction to prevent providing stale/incorrect labels. | ||
| */ | ||
| private static _currentTransactionLabel: unknown | undefined; |
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.
I think this property might work out even better if you put it on TreeCheckout - and it could be a member rather than be static. I know we discussed using a static because it's correct and it's easy - but if a non-static member is just as easy, then non-static is probably better style/convention.
Description
This PR exposes a user provided "label" object that can be accessed through
SchematizingSimpleTreeView.currentTransactionLabel, which can be accessed from the event callback incommitApplied.