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

TINY-11763: fix jumping cursor on delete within list #10184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michalnieruchalski-tiugo
Copy link
Collaborator

@michalnieruchalski-tiugo michalnieruchalski-tiugo commented Feb 20, 2025

Related Ticket: TINY-11763

Description of Changes:

  • Deleting an empty block within <li> would move cursor at the end of the <li>.
  • Deleting an empty block that is between two lists would throw an error when all of the elements were nested inside the same <li>.

Pre-checks:

  • Changelog entry added
  • Tests have been added (if applicable)
  • Branch prefixed with feature/, hotfix/ or spike/

Review:

  • Milestone set
  • Docs ticket created (if applicable)

GitHub issues (if applicable):

Summary by CodeRabbit

  • Bug Fixes and Improvements
    • Corrected cursor movement when deleting empty blocks within list items.
    • Resolved errors during deletions between nested list structures, enhancing editor robustness.
  • Tests
    • Added test cases to verify backspace and delete behaviors with empty <div> elements in list items.

Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

This update addresses issues related to cursor behavior and error handling when empty blocks within list items are deleted. It ensures that the cursor moves to the end of the <li> after deletion and prevents errors when deleting an empty block located between lists in the same <li>. Modifications in the deletion logic improve control flow in backspace and delete operations, and new test cases validate these scenarios.

Changes

File(s) Change Summary
.changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml Addresses cursor movement to the end of <li> after deleting an empty block and fixes error when deleting between lists within the same <li>.
modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts Updates functions backspaceDeleteFromListToListCaret and backspaceDeleteIntoListCaret with new checks for a valid commonAncestorParent and introduces nextCaretContainer to improve control flow and selection after deletion.
modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts Adds three new test cases to validate proper deletion of empty <div> elements inside list items and to ensure the correct cursor positioning and content preservation.

Suggested labels

status: escalated, Community PR, cla-signed

Suggested reviewers

  • TheSpyder
  • hamza0867
  • ltrouton
  • spocke
  • HAFRMO

Poem

In lines of code I softly tread,
With every hop, corrections spread.
The cursor leaps where lists abide,
Empty blocks no longer can hide.
I celebrate each refined edit—
A bouncy code trail, pure rabbit spirit!
🐰🌿


📜 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 c3f765a and 0321723.

📒 Files selected for processing (3)
  • .changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml (1 hunks)
  • modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts (3 hunks)
  • modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml
  • modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (3)

148-171: Well-structured test case that validates the cursor behavior fix!

The test case effectively verifies that:

  1. The empty div is correctly removed on backspace.
  2. The cursor is properly positioned at the end of "One".
  3. The HTML structure remains clean and valid.

173-196: Comprehensive test coverage for delete operation!

The test case effectively complements the backspace test by:

  1. Verifying empty div removal with delete key.
  2. Ensuring correct cursor positioning at the start of "Two".
  3. Maintaining proper HTML structure.

198-224: Excellent test coverage for nested list scenarios!

The test case effectively validates:

  1. Proper removal of empty div between ordered lists.
  2. Correct merging of adjacent ordered lists.
  3. Preservation of list item content and structure.

This test case is particularly valuable as it addresses the PR objective of fixing errors when deleting empty blocks between lists within the same <li>.


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>, 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 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
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@michalnieruchalski-tiugo michalnieruchalski-tiugo marked this pull request as ready for review February 20, 2025 08:06
@michalnieruchalski-tiugo michalnieruchalski-tiugo requested a review from a team as a code owner February 20, 2025 08:06
@michalnieruchalski-tiugo michalnieruchalski-tiugo requested review from spocke, TheSpyder, ltrouton, a team, lorenzo-pomili, hamza0867 and ztomaszyk and removed request for a team February 20, 2025 08:06
@michalnieruchalski-tiugo michalnieruchalski-tiugo added this to the 7.8.0 milestone Feb 20, 2025
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

🧹 Nitpick comments (1)
modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts (1)

191-194: Consider enhancing error handling.

While the check for commonAncestorParent prevents invalid operations, consider adding explicit error handling for edge cases.

-      if (!commonAncestorParent || dom.isChildOf(otherLi, commonAncestorParent)) {
+      if (!commonAncestorParent) {
+        editor.notificationManager.open({
+          text: 'Invalid list structure detected.',
+          type: 'error'
+        });
+        return false;
+      }
+      if (dom.isChildOf(otherLi, commonAncestorParent)) {
         return false;
       }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a63941d and a7b89e7.

📒 Files selected for processing (3)
  • .changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml (1 hunks)
  • modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts (3 hunks)
  • modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: Analyze (javascript)
  • GitHub Check: task-list-completed
🔇 Additional comments (5)
modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (3)

148-171: Well-structured test case!

The test thoroughly validates the backspace behavior when deleting an empty div within a list item, including proper cursor positioning.


173-196: Good test coverage for delete key behavior!

The test effectively mirrors the backspace test case, ensuring consistent behavior for both deletion directions.


198-224: Excellent edge case coverage!

The test effectively validates backspace behavior with nested lists, ensuring proper merging of adjacent ordered lists.

modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts (1)

236-238: Improved variable naming and selection logic!

The changes enhance code clarity with better variable naming and fix cursor positioning by using nextCaretContainer.

Also applies to: 239-239, 253-253

.changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml (1)

1-8: Clear and well-structured changelog entry!

The entry effectively communicates the fixed issues and follows the proper YAML format.

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

🧹 Nitpick comments (2)
modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (2)

173-196: Consider reducing test setup duplication.

While the test case is well-structured and validates the delete operation correctly, it shares identical initial content with the previous test. Consider extracting the common setup into a helper function to improve maintainability.

Example refactor:

const setupEmptyDivTest = (editor: Editor) => {
  editor.setContent('<ul>' +
    '<li>' +
      '<div>' +
        '<strong>One</strong>' +
        '<div><br></div>' +
      '</div>' +
      '<div><strong>Two</strong></div>' +
    '</li>' +
  '</ul>');
  TinySelections.setCursor(editor, [ 0, 0, 0, 1 ], 0);
};

198-224: Add cursor position assertion.

The test case thoroughly validates the content structure after backspace operation, but it's missing an assertion for the final cursor position. Adding this assertion would ensure the cursor behaves correctly when merging the lists.

Add cursor position assertion after the content assertion:

TinyAssertions.assertCursor(editor, [ 0, 0, 0, 1, 1 ], 0);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7b89e7 and c3f765a.

📒 Files selected for processing (3)
  • .changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml (1 hunks)
  • modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts (3 hunks)
  • modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changes/unreleased/tinymce-TINY-11763-2025-02-19.yaml
  • modules/tinymce/src/plugins/lists/main/ts/core/Delete.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
modules/tinymce/src/plugins/lists/test/ts/browser/BackspaceDeleteFromBlockIntoLiTest.ts (1)

148-171: Well-structured test case!

The test case thoroughly validates the backspace operation from an empty div within a list item, ensuring both content structure and cursor positioning are correct after the operation.

@@ -0,0 +1,7 @@
project: tinymce
kind: Fixed
body: Deleting an empty block within <li> would move cursor at the end of the <li>.
Copy link
Member

Choose a reason for hiding this comment

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

That is one long message. I wonder if you could split it up into two log items with the same issue ID since its fixing two bugs.

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.

2 participants