[lexical-markdown] Bug Fix: don't prefix a newline when a selection starts below the first block - #8960
Conversation
…tarts below the first block ## Description `$convertSelectionToMarkdownString` decided whether to prefix a block with `\n` by looking at the block's index among the root's children. Unselected children emit nothing, so that index is not the position in the output: when the selection starts below the top of the document the first emitted block still has `i > 0` and gets a newline prefixed, so the markdown opens with a blank line. The separator now tracks the previously emitted block. When every child is selected the previously emitted block is `children[i - 1]`, so the existing cases are unchanged. ## Test plan ### Before expected '\nSecond\n\nThird' to be 'Second\n\nThird' ### After 417 passed, prettier and tsc clean.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @luantaraschi! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Description
$convertSelectionToMarkdownStringdecides whether to prefix a block with\nby looking at the block's index among the root's children:Unselected children emit nothing, so the index is not the position in the output. When the selection starts below the top of the document, the first block that does get emitted still has
i > 0, and a newline is prefixed to it. The returned markdown then opens with a blank line.With three paragraphs and a selection covering only the last two:
The separator now tracks the previously emitted block instead of the previous child. When every child is selected, the previously emitted block is
children[i - 1], so nothing changes for the existing cases.createMarkdownExporthas the same shape but not the same bug:$exportTopLevelElementsonly returnsnullfor a node that is neither an element nor a decorator, which a root child never is, so every child there contributes to the output.Test plan
Before
After
pnpm run prettierandpnpm run tscare both clean.