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

[Lexical][Tables] Follow up on #6267 handle multi column delete crash on forward selection at end of the table #39

Open
wants to merge 2 commits into
base: cloned_main_8bc70
Choose a base branch
from

Conversation

local-dev-korbit-ai-mentor[bot]
Copy link

@local-dev-korbit-ai-mentor local-dev-korbit-ai-mentor bot commented Aug 15, 2024

What

fix crash on forward column deletion at the end of the table

Why

currently backward multiple column deletion at the end of the table works, forward multiple column deletion crashes, add handling for the same.

Before

Screen.Recording.2024-06-09.at.1.47.39.PM.mov

After

Screen.Recording.2024-06-09.at.1.47.20.PM.mov

Description by Korbit AI

What change is being made?

Add a test case to handle multi-column deletion at the end of a table and update the $deleteTableColumn__EXPERIMENTAL function to correctly move the selection when deleting columns.

Why are these changes being made?

These changes address a crash that occurs when deleting multiple columns with a forward selection at the end of a table. The test ensures the issue is fixed, and the code update corrects the selection movement logic to prevent the crash.

Summary by CodeRabbit

  • New Features

    • Added a test case for deleting columns in a table within the editor, improving test coverage for table manipulation.
  • Improvements

    • Enhanced the logic for determining the previous row when deleting a column, which may improve the user experience in selecting cells during column deletion.

Copy link
Author

Clone of the PR facebook/lexical#6279

Copy link

korbit-ai bot commented Aug 15, 2024

My review is in progress 📖 - I will have feedback for you in a few minutes!

Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

This update enhances the table manipulation capabilities within the editor by introducing a new test case for deleting columns from a table. Additionally, it modifies the logic in the $deleteTableColumn__EXPERIMENTAL function to refine how the previous row is determined during column deletions. These changes collectively improve both the testing framework and the underlying functionality related to table editing.

Changes

Files Change Summary
.../e2e/Tables.spec.mjs Added a test case for deleting columns from a table, validating functionality and checking HTML structure post-deletion.
.../LexicalTableUtils.ts Modified $deleteTableColumn__EXPERIMENTAL to adjust how previousRow is determined based on focus and anchor columns.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant TableUtils

    User->>Editor: Selects table columns to delete
    Editor->>TableUtils: Calls deleteTableColumns()
    TableUtils->>TableUtils: Determine previousRow based on focus and anchor columns
    TableUtils-->>Editor: Remove selected columns
    Editor-->>User: Update table display
Loading

🐇 In the meadow, columns sway,
Deleting rows in a merry play.
With tests now clear, and logic refined,
Our table's charm is well-defined!
Hops of joy, a code delight,
In the world of text, all feels just right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

I have reviewed your code and found 2 potential issues.

Comment on lines +639 to +642
const previousRow =
focusStartColumn < anchorStartColumn
? focusRowMap[focusStartColumn - 1]
: focusRowMap[anchorStartColumn - 1];
Copy link

Choose a reason for hiding this comment

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

category Functionality severity potentially major

The current implementation for moving the selection after deleting columns only handles the case where the focus column is less than the anchor column. To fix this, we should update the logic to handle both cases: when the focus column is less than the anchor column and when it's greater or equal. This will ensure that the selection is moved correctly regardless of the deletion direction.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Comment on lines +639 to +642
const previousRow =
focusStartColumn < anchorStartColumn
? focusRowMap[focusStartColumn - 1]
: focusRowMap[anchorStartColumn - 1];
Copy link

Choose a reason for hiding this comment

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

category Error Handling severity potentially major

The changes in the $deleteTableColumn__EXPERIMENTAL function do not include error handling for the case when focusRowMap[focusStartColumn - 1] or focusRowMap[anchorStartColumn - 1] is accessed with an out-of-bounds index. This could lead to a runtime error if focusStartColumn or anchorStartColumn is 0. Consider adding a check to ensure the indices are valid before accessing the array, and handle the case appropriately if they are out of bounds.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

@furwellness
Copy link
Owner

/review

Copy link

codiumai-pr-agent-free bot commented Aug 16, 2024

PR Reviewer Guide 🔍

(Review updated until commit 44f6e45)

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Key issues to review

Logic Update
The update to $deleteTableColumn__EXPERIMENTAL function introduces a new logic to determine the previousRow based on the comparison of focusStartColumn and anchorStartColumn. Ensure this logic correctly handles all edge cases, especially when columns are at the boundaries of the table.

Copy link

Persistent review updated to latest commit 44f6e45

@furwellness
Copy link
Owner

@coderabbitai review

Copy link

coderabbitai bot commented Aug 17, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8bc7050 and 44f6e45.

Files selected for processing (2)
  • packages/lexical-playground/tests/e2e/Tables.spec.mjs (1 hunks)
  • packages/lexical-table/src/LexicalTableUtils.ts (1 hunks)
Additional comments not posted (2)
packages/lexical-table/src/LexicalTableUtils.ts (1)

639-642: Enhance selection logic for column deletion.

The current implementation only handles the case where focusStartColumn is less than anchorStartColumn. Consider updating the logic to handle cases where focusStartColumn is greater than or equal to anchorStartColumn to ensure correct selection movement.

Additionally, ensure that accessing focusRowMap[focusStartColumn - 1] or focusRowMap[anchorStartColumn - 1] does not result in an out-of-bounds error. Consider adding checks to validate indices before accessing the array.

packages/lexical-playground/__tests__/e2e/Tables.spec.mjs (1)

2623-2670: New test case for forward column deletion looks good.

The test case effectively sets up the scenario, performs the column deletion, and verifies the expected HTML structure. This addition enhances test coverage for table manipulation features.

@furwellness
Copy link
Owner

Zero comments from coderabbit

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

Successfully merging this pull request may close these issues.

2 participants