Skip to content

Conversation

@hackerwins
Copy link
Member

@hackerwins hackerwins commented Sep 20, 2024

What does this PR do?

This PR fixes the issue of unintended <br> insertion while indenting bullets.

The problem has been noted in the test code where a <br> is inserted within the indentation of bullets, disrupting the expected behavior. Although a PR by HoffmannTom previously attempted to address this issue, it seems to have not resolved the root cause.

In this PR, I have reverted bullet.js to a version prior to HoffmannTom's fix and made direct amendments to the code in dom.js that triggers this problem.

@HoffmannTom

Can you please confirm whether the problems that previously occurs in this version?

Where should the reviewer start?

  • start on the src/summernote.js

How should this be manually tested?

  • N/A

Any background context you want to provide?

  • N/A

What are the relevant tickets?

Screenshot (if for frontend)

  • N/A

Checklist

  • Added relevant tests or not required
  • Didn't break anything

@coderabbitai
Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes involve updates to several JavaScript files and the package.json. The package.json file reflects a minor modification to the author's email address. In dom.js, a new parameter is added to the appendChildNodes function to control the insertion of <br> elements. The Bullet.js file sees improvements in list handling, including changes to sibling retrieval methods. Finally, a test case in Editor.spec.js is activated to ensure the functionality of list indentation is properly validated.

Changes

File Change Summary
package.json Updated the author's email address from a placeholder format to a standard format.
src/js/core/dom.js Modified appendChildNodes function to include a new parameter isSkipPaddingBlankHTML, affecting the logic for appending <br> elements.
src/js/editing/Bullet.js Updated methods for handling lists, including the use of previousSibling instead of previousElementSibling, and renamed findNextElementSiblings to findNextSiblings.
test/base/module/Editor.spec.js Activated a previously skipped test case for indenting and outdenting lists, ensuring it is now part of the test suite.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant ListHandler
    participant DOM

    User->>Editor: Indent list
    Editor->>ListHandler: Process indentation
    ListHandler->>DOM: Update DOM structure
    DOM-->>ListHandler: Confirm update
    ListHandler-->>Editor: Return updated state
    Editor-->>User: Display updated list
Loading

🐇 In the code, a change we see,
A new parameter, oh so free!
Lists now dance with sibling grace,
The tests are ready, in their place.
Hopping through the lines with glee,
Code and tests in harmony! 🌟


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

@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

Outside diff range and nitpick comments (1)
src/js/editing/Bullet.js (1)

Line range hint 168-259: LGTM!

The changes improve the readability and modularity of the code by using more concise syntax for mapping and wrapping list items and by using the splitTree function from the dom module. The updated implementation looks good.

Please fix the indentation issues flagged by the static analysis tool:

-              {
-                node: last.parentNode,
-                  offset: dom.position(last) + 1,
-                },
-                {
-                  isSkipPaddingBlankHTML: true,
-                },
-              )
+            {
+              node: last.parentNode,
+              offset: dom.position(last) + 1,
+            },
+            {
+              isSkipPaddingBlankHTML: true,
+            },
+          )
Tools
GitHub Check: build (20.x)

[warning] 194-194:
Expected indentation of 14 spaces but found 16


[warning] 195-195:
Expected indentation of 14 spaces but found 16


[warning] 196-196:
Expected indentation of 16 spaces but found 18


[warning] 197-197:
Expected indentation of 16 spaces but found 18


[warning] 198-198:
Expected indentation of 14 spaces but found 16


[warning] 199-199:
Expected indentation of 14 spaces but found 16


[warning] 200-200:
Expected indentation of 16 spaces but found 18


[warning] 201-201:
Expected indentation of 14 spaces but found 16


[warning] 202-202:
Expected indentation of 12 spaces but found 14

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e00991e and e73a885.

Files selected for processing (4)
  • package.json (1 hunks)
  • src/js/core/dom.js (1 hunks)
  • src/js/editing/Bullet.js (9 hunks)
  • test/base/module/Editor.spec.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Additional context used
GitHub Check: build (20.x)
src/js/editing/Bullet.js

[warning] 194-194:
Expected indentation of 14 spaces but found 16


[warning] 195-195:
Expected indentation of 14 spaces but found 16


[warning] 196-196:
Expected indentation of 16 spaces but found 18


[warning] 197-197:
Expected indentation of 16 spaces but found 18


[warning] 198-198:
Expected indentation of 14 spaces but found 16


[warning] 199-199:
Expected indentation of 14 spaces but found 16


[warning] 200-200:
Expected indentation of 16 spaces but found 18


[warning] 201-201:
Expected indentation of 14 spaces but found 16


[warning] 202-202:
Expected indentation of 12 spaces but found 14

Additional comments not posted (8)
src/js/editing/Bullet.js (5)

Line range hint 27-53: LGTM!

The changes simplify the logic for finding the previous list and appending paragraphs to it. The updated implementation looks good.


69-71: LGTM!

The change ensures that the margin value is parsed as an integer with a base of 10. The updated implementation looks good.


98-106: LGTM!

The changes improve the readability of the code by using a more concise syntax for filtering the list nodes. The updated implementation looks good.


129-130: LGTM!

The changes simplify the logic for finding the previous and next lists and improve the readability of the code by using the appendChildNodes function from the dom module. The updated implementation looks good.

Also applies to: 140-145


282-289: LGTM!

The changes align the function name and implementation with the changes made in the indent and wrapList functions. The use of nextSibling simplifies the logic and improves consistency. The updated implementation looks good.

test/base/module/Editor.spec.js (1)

140-140: Activated test case for list indentation and outdentation.

The test case that was previously skipped using it.skip has now been activated by changing it to it. This indicates that the underlying issue related to list indentation and outdentation has likely been fixed.

The activated test case thoroughly verifies the expected behavior of the editor when indenting and outdenting a list by:

  1. Inserting an ordered list.
  2. Indenting the list twice and verifying the expected HTML structure.
  3. Outdenting the list twice and verifying the expected HTML structure.

Activating this comprehensive test case helps ensure the correctness and reliability of the list indentation functionality.

src/js/core/dom.js (2)

423-423: Approve the addition of the new optional parameter isSkipPaddingBlankHTML.

The new parameter provides flexibility to control the behavior of appending <br> elements in specific scenarios while preserving the default behavior when the parameter is not provided.


428-428: Verify the impact of the new conditional check on the codebase.

The new conditional check !isSkipPaddingBlankHTML is added to determine whether to append a <br> element before a list when the current node is a <li> element with no child nodes.

Please ensure that the introduction of this check does not adversely affect any existing functionality or edge cases in the codebase where appendChildNodes is used.

Verification successful

The new conditional check has a limited and intended impact on list handling

The introduction of the !isSkipPaddingBlankHTML check in the appendChildNodes function appears to have a localized impact on the codebase. This change specifically addresses the case of appending a list to an empty <li> element, which is a unique scenario handled by this function.

Based on the codebase analysis:

  • The appendChildNodes function is used in various parts of the code for DOM manipulation and list operations.
  • The new conditional check is only present in one implementation of appendChildNodes.
  • No other occurrences of the specific pattern isLi($_) && $_.firstChild === null && isList($_) were found, suggesting this is a targeted fix.

The change doesn't seem to adversely affect existing functionality. However, to ensure the desired behavior:

  • Manually test list-related operations, particularly scenarios involving nested lists and empty list items.
  • Verify that the <br> element is correctly added when appending a list to an empty <li> element, and that this doesn't cause any unintended side effects in the rendered output.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the new conditional check in `appendChildNodes`.

# Test 1: Search for occurrences of `appendChildNodes` function calls.
# Expect: Identify places where the function is called and manually review if the new behavior is desirable.
rg --type javascript -A 5 $'appendChildNodes\('

# Test 2: Search for `<li>` elements followed by `<ul>` or `<ol>` elements.
# Expect: Identify scenarios where the new conditional check might affect the rendering.
rg --type html $'<li>[^<]*</li>\s*<(ul|ol)>'

Length of output: 129


Script:

#!/bin/bash

# Find JavaScript files and search for appendChildNodes function calls
echo "Searching for appendChildNodes function calls:"
fd -e js -x rg -A 5 'appendChildNodes\('

# Use ast-grep to find appendChildNodes function calls
echo "Using ast-grep to find appendChildNodes function calls:"
ast-grep --lang javascript --pattern 'appendChildNodes($_)'

# Use ast-grep to find list-related patterns
echo "Searching for list-related patterns:"
ast-grep --lang javascript --pattern 'isLi($_) && $_.firstChild === null && isList($_)'

Length of output: 1883

@thomass4t
Copy link
Contributor

Hello @hackerwins
I am not sure why previousElementSibling was reverted to previousSibling?
The original version of summernote had huge issues with whitespaces between the HTML elements.
Formatted HTML-Code caused much trouble. The code only worked with "non-pretty-printed HTML".
Thus, several lines were changed to ElementSiblings etc.
At first glance, it looks like a step back (?)
Currently, our clients are working with the version "#4679" and it works well so far.

@hackerwins
Copy link
Member Author

hackerwins commented Sep 20, 2024

@HoffmannTom @thomass4t

Hello, thank you for your feedback. After considering your comments, I'd like to summarize the current situation and propose a plan moving forward.

I recognize that bullet.js has undergone several patches, with the main issues being unwanted br insertions and problems related to pretty-printed HTML. I understand the complexity of these issues.

The primary reason for rolling back the code, including previousElementSibling, was the lack of test code with skipping in the previous patch, making it difficult to understand the rationale behind the changes. This was a precautionary decision.

https://github.com/summernote/summernote/pull/4679/files#r1756468136

I take your points about the previous version's issues with whitespaces between HTML elements and formatted HTML code seriously. I acknowledge that simply reverting to an earlier version may not be the best solution.

I kindly request that you submit a new PR specifically for the changes related to previousElementSibling. Please include comprehensive test code with this PR to demonstrate the functionality and purpose of these changes. This will help us understand the rationale behind the switch from previousSibling to previousElementSibling and its impact on whitespace and HTML formatting issues.

Once I receive your PR with the test code, I'll carefully review it and test it against the issues you've mentioned, particularly the problems with whitespaces and formatted HTML.

Your expertise is invaluable in resolving these issues. We appreciate your insights, especially regarding the stability of version #4679. I look forward to your continued involvement and feedback throughout this process.

@hackerwins hackerwins merged commit 1d1bb18 into develop Sep 20, 2024
@hackerwins hackerwins deleted the bullet-br branch September 20, 2024 23:14
@hackerwins hackerwins mentioned this pull request Sep 20, 2024
2 tasks
@hackerwins
Copy link
Member Author

@HoffmannTom @thomass4t

I would like to add stabilization work related to bullet in v0.9.0. Is it possible?

Screenshot 2024-09-21 at 12 51 44 PM

@thomass4t
Copy link
Contributor

thomass4t commented Sep 21, 2024

Hello @hackerwins
Thanks for your reply and suggestions. I fully agree that we need some test code to prevent introducing new bugs.
I would like to start with a broader view and give a big picture.
When we started using summernote several users complained and I started to dig into the reasons. It turned out, that there were two main issues:

  1. Working with pretty printed HTML code
  2. Working with bullet points
    (Next to some smaller issues like building problems etc.)

The fix for issue no 1 was:
a) Replacing the nextSibling methods with nextElementSibling
b) Replacing the previousSibling methods with previousElementSibling
to skip iterating over the whitespaces between the HTML elements like line breaks. Pretty-printed HTML worked afterward without errors.

The causes of issue no 2 were more hidden or complicated.
a) The function nodes (together with dom.walkPoint) was iterating over the DOM tree via a loop. It turned out that using a loop to traverse from start to end is error-prone and thus I introduced a recursive function walkDom and integrated this function into the node-function.
b) The splitTree method fails in several situations (like span-element within li-element). I haven't dug into the issue yet.

Now to the possible proceedings:
I am not familiar with vitest and the used frameworks. Currently, I wouldn't know for example how to set the cursor position and simulate an indent. Furthermore, I would have to keep up with the current development as I can only work from time to time on this project or issue.

Another possibility would be that I revert to the current head of the main branch and report HTML snippets that fail when using certain functions like indent/outdent/creating a line break etc. You would have control and an eye over the global architecture.

Any thoughts about this?

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.

3 participants