-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Bug: $convertFromMarkdownString triggers the breakdown of the editor #5385
Comments
This bug happens as following scenario within this function:
suggestions A.
function importTextMatchTransformers(
textNode_: TextNode,
textMatchTransformers: Array<TextMatchTransformer>,
referencedNode?: TextNode,
) {
let textNode = textNode_;
let isReferencedNodeReplaced = false;
// ...
// ...
if (leftTextNode) {
const isTextNodeReplaced = importTextMatchTransformers(
leftTextNode,
textMatchTransformers,
textNode,
);
if (isTextNodeReplaced) {
textNode.__text = '';
}
}
transformer.replace(replaceNode, match);
if (referencedNode === replaceNode) {
isReferencedNodeReplaced = true;
}
continue mainLoop;
}
break;
}
return isReferencedNodeReplaced;
} Suggestion B.
I think this way is a less error-prone and simpler approach. function importTextMatchTransformers(
textNode_: TextNode,
textMatchTransformers: Array<TextMatchTransformer>,
) {
let textNode = textNode_;
mainLoop: while (textNode) {
for (const transformer of textMatchTransformers) {
// ....
const startIndex = match.index || 0;
const endIndex = startIndex + match[0].length;
let replaceNode, newTextNode;
if (startIndex === 0) {
[replaceNode, textNode] = textNode.splitText(endIndex);
} else {
[, replaceNode, newTextNode] = textNode.splitText(startIndex, endIndex);
}
if (newTextNode) {
importTextMatchTransformers(newTextNode, textMatchTransformers);
}
transformer.replace(replaceNode, match);
continue mainLoop;
}
break;
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lexical version: latest (0.12.5)
Steps To Reproduce
Link to code example: can reproduce in the Playground
The current behavior
before-convertfrommarkdown.mov
The expected behavior
it should convert to link node and image node
The text was updated successfully, but these errors were encountered: