Skip to content

Implement element deletion functionality in InfiniteCanvas#94

Merged
zytact merged 1 commit intomainfrom
delete
Mar 11, 2025
Merged

Implement element deletion functionality in InfiniteCanvas#94
zytact merged 1 commit intomainfrom
delete

Conversation

@zytact
Copy link
Copy Markdown
Owner

@zytact zytact commented Mar 11, 2025

Add the ability to delete selected elements in the InfiniteCanvas, triggered by the Delete key when in move mode. This enhances user interaction by allowing for easier management of canvas elements.

Summary by CodeRabbit

  • New Features
    • Enabled canvas element deletion using the keyboard's "Delete" key. Users can now quickly remove selected shapes, with the canvas state and history automatically updated.
    • Improved interaction handling to ensure smooth deletion and clear selection feedback.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
strokeshare ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2025 10:31pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 11, 2025

Walkthrough

The changes add a new function, handleElementDelete, to delete selected shapes from the canvas based on their type. The function filters out the corresponding shape from state arrays, records the change in history, and resets the selection and transform controls. Additionally, the handleKeyDown event listener is updated to call this function when the 'Delete' key is pressed, with the effect hook updated to include the new function as a dependency.

Changes

File(s) Change Summary
components/ui/InfiniteCanvas.tsx - Added handleElementDelete function to remove selected shapes from corresponding arrays based on type.
- Updated handleKeyDown to invoke deletion on 'Delete' key press.
- Updated useEffect dependencies to include the new deletion function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Canvas
    participant History

    User->>Canvas: Press 'Delete' key
    Canvas->>Canvas: handleKeyDown(event)
    Canvas->>Canvas: Call handleElementDelete()
    Canvas->>Canvas: Identify shape type & filter array
    Canvas->>Canvas: Reset transformer & clear selection
    Canvas->>History: addToHistory(updated state)
Loading

Possibly related PRs

Poem

I'm a rabbit, hopping with glee,
Deleting shapes has set my art free.
With a key press and swift command,
Canvas cleansed by careful hand.
In circles, lines, and images,
Every change is a joy that brings 🎨✨!
Hop along to our new canvas song.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
components/ui/InfiniteCanvas.tsx (3)

474-527: Good implementation of the element deletion functionality.

The handleElementDelete function is well-structured with a clear switch statement to handle different shape types. It correctly filters out the selected element from the appropriate state array, updates the state, and records the change in history. The function also properly cleans up by resetting the transformer and clearing the selection state.

Consider adding visual feedback when an element is deleted to improve user experience. This could be a simple toast notification or subtle animation.

 const handleElementDelete = () => {
     if (!selectedId || !selectedShape) return;

     switch (selectedShape) {
         case 'line': {
             const lineIndex = parseInt(selectedId);
             const updatedLines = lines.filter(
                 (_, index) => index !== lineIndex,
             );
             setLines(updatedLines);
             addToHistory(updatedLines);
+            // TODO: Add visual feedback that the element was deleted
             break;
         }
         // Other cases...
     }

     resetTransformer();
     setSelectedId(null);
     setSelectedShape(null);
 };

474-527: Consider adding confirmation for deletion.

Currently, elements are deleted immediately when the Delete key is pressed. For better user experience, especially when dealing with complex creations, consider adding a confirmation dialog for deletion operations.

You could implement a simple confirmation mechanism, either using a modal dialog or a temporary "confirm delete" state:

 const handleElementDelete = () => {
     if (!selectedId || !selectedShape) return;
+    
+    // Option 1: Use browser's built-in confirm dialog
+    if (!window.confirm('Are you sure you want to delete this element?')) {
+        return;
+    }
+    
+    // Option 2: For a more integrated approach, could set a state and render a custom confirmation UI
+    // if (!confirmDeleteState) {
+    //     setConfirmDeleteState(true);
+    //     return;
+    // }
+    // setConfirmDeleteState(false);

     switch (selectedShape) {
         // Cases...
     }
     // ...
 };

474-527: Multi-select deletion capability could be useful.

Currently, the implementation only deletes one selected element at a time. For a more powerful editing experience, consider adding support for deleting multiple selected elements simultaneously.

This would require extending the current selection model to support multiple selections, perhaps by changing selectedId to an array of IDs and updating the transformer to work with multiple nodes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2566e82 and 2cbf221.

📒 Files selected for processing (1)
  • components/ui/InfiniteCanvas.tsx (3 hunks)
🔇 Additional comments (2)
components/ui/InfiniteCanvas.tsx (2)

553-558: Clean implementation of Delete key handler.

The Delete key handler is well-integrated into the existing handleKeyDown function. It correctly checks if the app is in move mode before proceeding with deletion, which aligns with the PR objective of implementing this functionality specifically for move mode.


572-572: Proper dependency management.

Adding handleElementDelete to the dependency array of the useEffect hook ensures that the event listener always uses the latest version of the function. This is important for maintaining consistent behavior when the component re-renders.

@zytact zytact merged commit b68bea5 into main Mar 11, 2025
4 checks passed
@zytact zytact deleted the delete branch March 11, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant