Bug Fix : fix cursor looping and incorrect paragraph insertion after tables#8030
Bug Fix : fix cursor looping and incorrect paragraph insertion after tables#8030Jynx2004 wants to merge 19 commits intofacebook:mainfrom
Conversation
…e $createParagraphNode
Removed unnecessary checks and code related to text node styles.
Table selection issue
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
This isn't a complete workaround and it does not add any tests to show that it works as expected
| const elementBefore = | ||
| anchorNode.__prev && $getNodeByKey(anchorNode.__prev); |
There was a problem hiding this comment.
This is better written as anchorNode.getPreviousSibling()
There was a problem hiding this comment.
In my latest merge request i have used anchorNode.getPreviousSibling() instead of anchorNode.__prev and $getNodeByKey(anchorNode.__prev)
| if (elementBefore && elementBefore.__type === 'table') { | ||
| return; | ||
| } |
There was a problem hiding this comment.
This is not an acceptable solution because LexicalSelection shouldn't know about tables and the type of a table could be any string (in situations where a node override is used to replace TableNode with a subclass)
There was a problem hiding this comment.
How can we identify the paragraph node which is just after the table in hierarchy other than the above method ?
If we recognize it then we can prevent deletion of it which resolves the bug.
There was a problem hiding this comment.
Usually this would be done by implementing the functionality in one of the table plugins.
There was a problem hiding this comment.
Will work on improving elementBefore && elementBefore.__type === 'table'
There was a problem hiding this comment.
The function $TableNode checks whether a given node is an instance of class TableNode but we cannot use it in LexicalSelection .
There was a problem hiding this comment.
Usually this would be done by implementing the functionality in one of the table plugins.
Issue lies in the paragraphNode which is inserted below the table when the table is created . When we delete the paragraph then the cursor gets stuck in a loop when we click the right arrow. So we need to prevent the deletion of that node so that the bug gets resolved.
There was a problem hiding this comment.
Right, this workaround should not be in this file at all.
…exical into table_selection_issue
Table selection issue
Removed comments regarding deletion prevention before a table.
Description
This PR fixes an issue where cursor navigation becomes inconsistent when a table is the final block in the document.
Fixes #7999
Problem
When a table is the last node and all content after it is deleted:
This makes it difficult for users to understand how to add content after a table.
Cause
When there is no text in the direction of navigation, Lexical attempts to explore adjacent nodes. If the previous node is a table, this logic re-enters table selection and causes the cursor to cycle back into the table.
Fix
Short-circuit navigation/deletion logic when:
This prevents Lexical from re-entering table selection logic and allows the cursor to correctly move and remain below the table.
Result
Impact
Primarily a polish improvement, but significantly improves usability and prevents user confusion when editing content after tables.