-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[lexical-link] Feature: Merging two identical links into one node #8168
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
Open
Jynx2004
wants to merge
17
commits into
facebook:main
Choose a base branch
from
Jynx2004:lexical_link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−2
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
992433b
fix:handle the missing link on the draggable image
Jynx2004 fcc767f
fix:Code Block formatting applies to unintended adjacent lines
Jynx2004 d59b925
revert_changes
Jynx2004 354ead8
table break changes
Jynx2004 baead42
utils changed to the main one
Jynx2004 e2caf5a
equation_changes
Jynx2004 9ceaaec
refactor: simplify applyTableHandlers by removing page-break handling…
Jynx2004 5ea306f
feat: add style handling for text nodes in $createNodesFromDOM
Jynx2004 3cbf85c
refactor: remove InlineParagraphNode and update EquationsPlugin to us…
Jynx2004 4785a28
fix: ensure style is applied to the first text node in $createNodesFr…
Jynx2004 67719f7
fix: prevent deletion when the previous element is a table in RangeSe…
Jynx2004 eabdd08
Refactor text node style handling logic
Jynx2004 5bff69c
fix: prevent deletion of paragraph before table in RangeSelection
Jynx2004 16711ef
Merge branch 'table_selection_issue' of https://github.com/Jynx2004/l…
Jynx2004 26b86a3
fix: handle insertion of nodes within links in $insertGeneratedNodes
Jynx2004 8dceaec
fix: remove unnecessary check for deletion prevention before table in…
Jynx2004 674b899
Merge branch 'main' into lexical_link
Jynx2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,15 +225,62 @@ export function $insertGeneratedNodes( | |
| nodes: Array<LexicalNode>, | ||
| selection: BaseSelection, | ||
| ): void { | ||
| // If the selection is entirely within a link, | ||
| // we want to insert the text content of the nodes into the link | ||
| function isSameLinkParent(sel: BaseSelection): boolean { | ||
| const points = sel.getStartEndPoints(); | ||
| if (points == null) { | ||
| return false; | ||
| } | ||
|
|
||
| const startPoint = points[0]; | ||
| const endPoint = points[1]; | ||
|
|
||
| if (startPoint == null || endPoint == null) { | ||
| return false; | ||
| } | ||
|
|
||
| const startNode = startPoint.getNode(); | ||
| const endNode = endPoint.getNode(); | ||
|
|
||
| if (startNode == null || endNode == null) { | ||
| return false; | ||
| } | ||
|
|
||
| const parentElementBefore = startNode.getParent(); | ||
| const parentElementAfter = endNode.getParent(); | ||
|
|
||
| if (parentElementBefore == null || parentElementAfter == null) { | ||
| return false; | ||
| } | ||
|
|
||
| return ( | ||
| parentElementAfter.getType() === 'link' && | ||
| parentElementAfter.getType() === parentElementBefore.getType() | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| !editor.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, { | ||
| nodes, | ||
| selection, | ||
| }) | ||
| ) { | ||
| selection.insertNodes(nodes); | ||
| $updateSelectionOnInsert(selection); | ||
| if (isSameLinkParent(selection)) { | ||
| // Only insert the content of the first text node | ||
| const textNodes = nodes.filter((node) => $isTextNode(node)); | ||
|
|
||
| if (textNodes.length > 0) { | ||
| const firstText = textNodes[0]; | ||
| selection.insertText(firstText.getTextContent()); | ||
| $updateSelectionOnInsert(selection); | ||
| } | ||
| } else { | ||
| selection.insertNodes(nodes); | ||
| $updateSelectionOnInsert(selection); | ||
| } | ||
|
Comment on lines
+271
to
+281
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look correct since all other nodes will be discarded if one TextNode exists. It also ignores any formatting. |
||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't an acceptable approach. @lexical/clipboard can't depend on @lexical/link, and you can't use getType to check the type of a node since nodes can be subclasses with a different type.