Skip to content

Conversation

@mmjinglin163
Copy link
Contributor

Remove the operation from the history when the splat is removed

@willeastcott willeastcott requested review from Copilot and slimbuck and removed request for slimbuck September 19, 2025 13:11
@willeastcott willeastcott added the enhancement New feature label Sep 19, 2025
Copy link
Contributor

Copilot AI left a 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.elementRemoved to trigger history cleanup
  • Implemented removeBySplat method 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.

removeBySplat(element: Element) {
function isRelatedToSplat(editOp: EditOp): boolean {
if (editOp?.splat === element) return true;
// 处理 MultiOp
Copy link

Copilot AI Sep 19, 2025

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

Suggested change
// 处理 MultiOp
// Handle MultiOp

Copilot uses AI. Check for mistakes.
Comment on lines 41 to 43
if ((editOp as any).ops instanceof Array) {
return (editOp as any).ops.some(isRelatedToSplat);
}
Copy link

Copilot AI Sep 19, 2025

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.

Copilot uses AI. Check for mistakes.
@slimbuck
Copy link
Member

Thanks so much for this PR.

I will hopefully get a chance to test and merge it within the next few days!

@slimbuck
Copy link
Member

slimbuck commented Oct 2, 2025

Hey @mmjinglin163 ,

I would like to suggest a few changes to this PR:

  • register for scene.elementRemoved directly in EditHistory constructor
  • add a function toEditOp interface for testing whether it applies to the supplied Element instance
  • implement the function where necessary for StateOp and MultiOp

What do you think, does this sound reasonable?

If you could make these changes that would be great, otherwise I can too.

Thanks again!

@mmjinglin163
Copy link
Contributor Author

You're right—these changes will make the structure cleaner and reduce coupling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants