motla / vue-document-editor

:page_facing_up: Paper-sized WYSIWYG document editor for Vue apps
https://motla.github.io/vue-document-editor/
MIT License
313 stars 70 forks source link

issue #47 resolved #48

Open Yogesh0627 opened 2 months ago

Yogesh0627 commented 2 months ago

Pull Request Description: Fix for Infinite Recursion in move_children_forward_recursively for Long Continuous Words

Problem Description: This pull request addresses a bug in the move_children_forward_recursively function, which resulted in infinite recursion when handling long continuous words that could not fit on a page. The original logic would attempt to move overflowing content to the next page, but for long continuous words without spaces, the content would still not fit, leading to an endless loop.

Solution Implemented: In this fix, additional logic has been introduced to specifically handle long continuous words in the following way:

Long Word Detection:

A check is introduced to identify when a text node contains a long continuous word without spaces. If such a word is detected, it is split into manageable parts. Word Handling:

The word is split into segments, with the first portion remaining on the current page and the latter part being moved to the next page. This ensures that the content doesn't infinitely overflow and cause a recursive loop. Recursive Handling:

New Changes Compared to Original Code: Handling Long Continuous Words: A mechanism to detect and split long continuous words, which prevents the infinite recursion issue. Graceful Word Wrapping: For long words that cannot fit on a single page, the content is split and moved across pages, rather than attempting to force the entire word onto the next page. Preservation of Recursion Logic: The overall recursive movement and cloning logic remain intact but are now equipped to handle long text nodes without causing performance or overflow issues. This fix effectively prevents infinite recursion when the library tries to move long continuous words between pages while preserving the functionality for other types of content like images, headers, and tables.

Testing & Verification: This solution has been tested with various cases, including:

Long continuous words. Regular text nodes with spaces. Various HTML elements like headers, images, and tables. The recursive handling for normal text and sub-child elements remains largely the same but includes safeguards to avoid the infinite loop when dealing with long words. If a word is too long to fit on a single page, it is broken and moved piece by piece across pages. Element Cloning & Movement:

Elements such as headers, images, or other non-text nodes are handled as before, being moved or cloned to the next page when required. The recursive cloning process is maintained with the introduction of additional checks to ensure that long text nodes are handled properly and do not disrupt the flow of elements.

Yogesh0627 commented 2 months ago

i have optimized my approach for the solution

Yogesh0627 commented 1 month ago

hey can you please give feedback for my implementation for the solution .

motla commented 1 month ago

Hi @Yogesh0627 Thanks a lot for your contribution. I'm sorry these times are a bit complicated I'm overwhelmed with several due dates, but it's definitely in my todo list 👍 I hope I can check it soon. Romain