Skip to content

[WIKI-277] fix: unable to delete last table column/row in editor#7389

Merged
sriramveeraghanta merged 5 commits intopreviewfrom
fix/column-delete
Jul 14, 2025
Merged

[WIKI-277] fix: unable to delete last table column/row in editor#7389
sriramveeraghanta merged 5 commits intopreviewfrom
fix/column-delete

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Jul 11, 2025

Description

This PR fixes the bug where users are unable to delete the last column/row of a table.

Cause: By default, ProseMirror doesn't allow a table to exist without any column/row.

Solution: If the user tries to delete the last column/row, we delete the entire table, bypassing the default logic.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Improved table editing: Deleting the last remaining column or row in a table now removes the entire table automatically.
  • Bug Fixes

    • Enhanced reliability when deleting columns and rows in tables, ensuring consistent behavior when only one column or row remains.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

The changes replace the original deleteColumn and deleteRow commands in the table extension with new utility commands deleteColumnOrTable and deleteRowOrTable. These commands delete the entire table if only one column or row remains; otherwise, they delete the selected column or row. The deleteTable command remains unchanged. Additionally, the isCellSelection utility was moved and refactored into a helpers module.

Changes

File(s) Change Summary
packages/editor/src/core/extensions/table/table/table.ts Replaced imports and command mappings for deleteColumn and deleteRow with deleteColumnOrTable and deleteRowOrTable.
packages/editor/src/core/extensions/table/table/utilities/delete-column.ts Added deleteColumnOrTable command to delete either a column or the entire table based on column count.
packages/editor/src/core/extensions/table/table/utilities/delete-row.ts Added deleteRowOrTable command to delete either a row or the entire table based on row count.
packages/editor/src/core/extensions/table/table/utilities/helpers.ts Added isCellSelection utility function as a type guard for cell selections.
packages/editor/src/core/extensions/table/table/utilities/is-cell-selection.ts Deleted old isCellSelection utility file.
packages/editor/src/core/components/menus/bubble-menu/root.tsx Changed import path for isCellSelection and reordered type imports.
packages/editor/src/core/extensions/table/table/utilities/delete-table-when-all-cells-selected.ts Changed import path for isCellSelection.
packages/editor/src/index.ts Updated export source of isCellSelection to new helpers module.

Suggested labels

ready to merge

Suggested reviewers

  • Palanikannan1437
  • sriramveeraghanta

Poem

A column stands, alone and proud,
But if it’s one, we clear the crowd!
With bunny paws, we sweep the floor,
Table or column—gone, no more.
A hop, a skip, a tidy space,
Thanks to new code in just the right place!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9198a43 and 1729ff7.

📒 Files selected for processing (7)
  • packages/editor/src/core/components/menus/bubble-menu/root.tsx (1 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/delete-column.ts (1 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/delete-row.ts (1 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/delete-table-when-all-cells-selected.ts (1 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/helpers.ts (1 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/is-cell-selection.ts (0 hunks)
  • packages/editor/src/index.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/editor/src/core/extensions/table/table/utilities/is-cell-selection.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/editor/src/core/extensions/table/table/utilities/delete-table-when-all-cells-selected.ts
  • packages/editor/src/index.ts
  • packages/editor/src/core/components/menus/bubble-menu/root.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/editor/src/core/extensions/table/table/utilities/delete-column.ts
  • packages/editor/src/core/extensions/table/table/utilities/delete-row.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/editor/src/core/extensions/table/table/utilities/helpers.ts (1)
packages/editor/src/index.ts (1)
  • isCellSelection (18-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/editor/src/core/extensions/table/table/utilities/helpers.ts (2)

1-2: LGTM: Imports are appropriate and necessary.

The imports correctly bring in the required types from the ProseMirror packages for the type guard implementation.


4-9: LGTM: Well-implemented type guard with excellent documentation.

The function implementation is clean and follows TypeScript best practices:

  • Comprehensive JSDoc documentation
  • Proper type guard syntax with selection is CellSelection
  • Appropriate use of instanceof for runtime type checking
  • Consolidating this utility into a centralized helpers module improves code organization
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@makeplane
Copy link

makeplane bot commented Jul 11, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

Copy link
Contributor

@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 (1)
packages/editor/src/core/extensions/table/table/utilities/delete-column.ts (1)

15-18: Consider improving table node retrieval robustness.

The current logic uses selection.$anchorCell.start(-1) and state.doc.nodeAt(tableStart - 1) to get the table node. While this works, it relies on specific document structure assumptions that could be fragile.

Consider using a more robust approach:

-  // Get the ProseMirrorTable and calculate total columns
-  const tableStart = selection.$anchorCell.start(-1);
-  const selectedTable = state.doc.nodeAt(tableStart - 1);
+  // Get the ProseMirrorTable and calculate total columns
+  const tableStart = selection.$anchorCell.start(-1);
+  const selectedTable = state.doc.nodeAt(tableStart - 1);
+  
+  // Alternative: More robust table node retrieval
+  // const tablePos = selection.$anchorCell.pos;
+  // const selectedTable = state.doc.resolve(tablePos).node(-1);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86f3ff1 and 9ec29c2.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/table/table/table.ts (2 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/delete-column.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/editor/src/core/extensions/table/table/table.ts (1)
packages/editor/src/core/extensions/table/table/utilities/delete-column.ts (1)
  • deleteColumnOrTable (4-37)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
packages/editor/src/core/extensions/table/table/utilities/delete-column.ts (4)

1-3: LGTM: Imports are correct and necessary.

The imports include all required types and functions from TipTap for table operations.


4-12: LGTM: Function signature and selection validation are correct.

The function correctly implements the TipTap Command pattern and properly validates that the current selection is a CellSelection before proceeding.


31-36: LGTM: Decision logic correctly implements the PR objective.

The logic correctly deletes the entire table when only one column remains, and falls back to normal column deletion otherwise. This successfully addresses the PR objective of handling the "unable to delete last column" issue.


20-28: Validate totalColumns logic for all table configurations

The current implementation in packages/editor/src/core/extensions/table/table/utilities/delete-column.ts (lines 20–28) only sums colspan values in the first row to determine the total number of columns. This can undercount or miscount tables that use rowspans or have differing column structures in later rows.

Please verify and handle edge cases such as:

  • First-row cells using rowspan, masking columns that only appear beneath
  • Later rows introducing extra columns not represented in the first row
  • Empty or missing cells in the first row
  • Complex combinations of rowspan and colspan

To ensure accuracy, consider using ProseMirror’s TableMap to compute the full table matrix and derive the true column count before deciding between deleting the entire table or a single column.

packages/editor/src/core/extensions/table/table/table.ts (2)

29-29: LGTM: Import change is correct.

The import correctly references the new deleteColumnOrTable utility function from the local utilities directory.


143-143: LGTM: Command mapping correctly implements the new behavior.

The deleteColumn command now uses deleteColumnOrTable directly, which maintains the same interface while providing the enhanced functionality to delete the entire table when only one column remains.

@aaryan610 aaryan610 changed the title [WIKI-277] fix: unable to delete last table column in editor [WIKI-277] fix: unable to delete last table column/row in editor Jul 11, 2025
Copy link
Contributor

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ec29c2 and 5931475.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/table/table/table.ts (3 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/delete-row.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/editor/src/core/extensions/table/table/table.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/editor/src/core/extensions/table/table/utilities/delete-row.ts (5)

1-2: LGTM: Clean imports for table operations.

The imports are appropriate and include all necessary components for the table manipulation functionality.


4-6: LGTM: Proper TipTap command structure.

The function signature follows the standard TipTap command pattern with proper typing and destructuring.


9-12: LGTM: Appropriate selection validation.

The validation correctly checks for CellSelection and returns false when not applicable, following TipTap command conventions.


14-18: LGTM: Standard table node retrieval with proper null checking.

The table retrieval logic correctly uses ProseMirror's node access patterns and includes appropriate null checking.


28-34: LGTM: Correct conditional deletion logic.

The implementation properly handles the core requirement - deleting the entire table when only one row remains, otherwise falling back to normal row deletion behavior.

Copy link
Member

@iam-vipin iam-vipin left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@sriramveeraghanta sriramveeraghanta merged commit a427367 into preview Jul 14, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix/column-delete branch July 14, 2025 11:57
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
* fix: delete column not working

* refactor: delete column commad

* fix: delete last row logic

* refactor: row count logic

* refactor: isCellSelection utility function
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.

3 participants