-
Notifications
You must be signed in to change notification settings - Fork 375
Remove the operation from the history when the splat is removed #585
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
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.
Pull Request Overview
This PR adds functionality to clean up edit history when elements are removed from the scene. When a splat (element) is deleted, the corresponding operations in the edit history are automatically removed to prevent memory leaks and maintain history consistency.
Key changes:
- Added event handler for
scene.elementRemovedto trigger history cleanup - Implemented
removeBySplatmethod to filter out operations related to deleted elements - Added proper cursor adjustment and event firing after history cleanup
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/editor.ts | Added event listener to handle element removal and trigger history cleanup |
| src/edit-history.ts | Added removeBySplat method to remove operations associated with deleted elements |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/edit-history.ts
Outdated
| removeBySplat(element: Element) { | ||
| function isRelatedToSplat(editOp: EditOp): boolean { | ||
| if (editOp?.splat === element) return true; | ||
| // 处理 MultiOp |
Copilot
AI
Sep 19, 2025
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.
The comment is in Chinese. Consider using English for consistency with the rest of the codebase: // Handle MultiOp
| // 处理 MultiOp | |
| // Handle MultiOp |
src/edit-history.ts
Outdated
| if ((editOp as any).ops instanceof Array) { | ||
| return (editOp as any).ops.some(isRelatedToSplat); | ||
| } |
Copilot
AI
Sep 19, 2025
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.
Using any type casting defeats TypeScript's type safety. Consider defining a proper interface for MultiOp or use a type guard to check for the ops property more safely.
|
Thanks so much for this PR. I will hopefully get a chance to test and merge it within the next few days! |
|
Hey @mmjinglin163 , I would like to suggest a few changes to this PR:
What do you think, does this sound reasonable? If you could make these changes that would be great, otherwise I can too. Thanks again! |
|
You're right—these changes will make the structure cleaner and reduce coupling. |
Remove the operation from the history when the splat is removed