Raise lexical version and use it to improve text selection#949
Closed
doxman wants to merge 3 commits into
Closed
Conversation
Contributor
|
@doxman thanks for raising that, it's indeed a meaningful improvement, and keeping up with lexical has been long overdue. It also accumulated a bunch of things that had to be addressed for the upgrade to work properly (and take advantage of some new Lexical features). I spent some fable/sol tokens on the upgrade specifics, taking your finding into account, and merged #950 . I would appreciate if you give it some testing, let me know if you discover anything. Regards, |
pull Bot
pushed a commit
to LeeeeeeM/editor
that referenced
this pull request
Jul 19, 2026
Capture the changelog assessment, PR mdx-editor#949 analysis, bounded child PRPs, spikes, execution notes, and independently verified evidence. Preserve the decision to keep the public MDAST visitor pipeline authoritative and leave lexical/mdast for a separate initiative.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Upgrades
lexicalfrom0.35.0to0.48.0.This enables the use of
$convertSelectionToMarkdownString, which was introduced in0.45.0. Used this to makegetSelectionAsMarkdownmuch more precise:Input (select the lines with A and B):
Output (old implementation):
Output (new implementation):
There were two common GFM nodes (thematic breaks, and tables) that were omitted by the previous implementation, and not automatically handled by the
lexicalfunction (because they are not core lexical functionality).Solved this by writing custom
Transformers for each of these, and feeding them togetSelectionAsMarkdownif the appropriate plugins are turned on.In the process, gave
tablePlugina name so that we can check whether it's enabled, and a subscription totoMarkdownExtensions$so that the transformer can pull them out of a cache and feed them to itstoMarkdown()call.Files not directly related to the main change
I did not delve too deeply into these, we can discuss a more proper fix if they are a concern
tsconfig.json: The higher version oflexicalrequired a change tomoduleResolution; I went with "bundler" as the smallest change.src/mdastUtilHtmlComment.ts: The stricter TS module resolution caused issues withtypesandcodesdue to their weird types; added a typecast to fix thissrc/plugins/codeblock/CodeBlockNode.tsx: Now clashes with Lexical's types. Usedas unknown ascasting trick to silence.src/plugins/thematic-break/: Lexical has deprecated the thematic break members inlexical/reactand recommendslexical/extensioninstead. However, they are not interchangeable - for exampleHorizontalRulePluginis a component whileHorizontalRuleExtensionis a config object. I only moved over the objects I could confirm are the same between the two, and lefteslint-disablecomments on the rest for now.Additional edge case
There was one edge-case with selection that I found but did not fix. If a link is partially selected without including the first character, and no other lines are selected, then selection is returned as empty (no error logs or anything).
I think this is because the
LINKtransformer's regex only identifies a link node if the lead character is included; at least, when it's the only selected node. Since this is probably a rare case, I think it's better to wait forlexicalto fix it upstream, than make a handrolled solution to patch it.