Skip to content
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

fix(pte): preserve block key when pressing enter at start of block #6521

Merged
merged 6 commits into from
May 2, 2024

Conversation

pedrobonamin
Copy link
Contributor

@pedrobonamin pedrobonamin commented Apr 30, 2024

Description

fixes edx-1056.

Changes:

  • Adds new "plugin" withInsertBreak which handles the case of pressing enter at the start of a block.
  • Moves createEmptyBlock function to the editor utils, allowing ease of reuse.

Issue:
When moving a block by placing the cursor at the beginning of a block and pressing “Enter” – a new _key is currently generated for that block. This is problematic because comments are linked to specific blocks through the _key. If a new _key is generated when moving the block in this way, all comments associated with that block will disappear. This occurs because the _key value in the comment document no longer references any block content by its _key.

This PR updates the behaviour when pressing enter key in the PTE editor, if the cursor is at the start of the block, instead of doing a split_node operation it will do a insert_node operation. This will preserve the key of the current block.

Challenge: focus handling is not automatically updated by Slate and it keeps the cursor in the new inserted block instead of the block the user was. This is fixed by this change , forcing the focus path to the next block, which is the actual block, because a new block was inserted in the previous position https://github.com/sanity-io/sanity/pull/6521/files#diff-35c7a342daeb53013561d14759571db71e13c8782293a91e14f254608dbdb439R29-R32

It can be tested here https://test-studio-git-edx-1056.sanity.build/test/structure/input-standard;portable-text;pt_allTheBellsAndWhistles;e93f598b-8ec4-4bed-87aa-ab855210ed0e

What to review

Testing

Notes for release

Copy link

vercel bot commented Apr 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview May 2, 2024 10:33am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 2, 2024 10:33am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 2, 2024 10:33am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 2, 2024 10:33am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Apr 30, 2024

Component Testing Report Updated May 2, 2024 10:38 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 34s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 27s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 20s 6 3 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 3s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 5s 18 0 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 22s 9 0 0

Copy link
Member

@skogsmaskin skogsmaskin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work @pedrobonamin!

Thank you for this.

@pedrobonamin pedrobonamin added this pull request to the merge queue May 2, 2024
Merged via the queue into next with commit 7df5396 May 2, 2024
37 checks passed
@pedrobonamin pedrobonamin deleted the edx-1056 branch May 2, 2024 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants