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

feat(portable-text-editor): determine if selection is made backward #5807

Merged
merged 3 commits into from
Feb 21, 2024

Conversation

skogsmaskin
Copy link
Member

@skogsmaskin skogsmaskin commented Feb 20, 2024

Description

Add .backward? on EditorSelection to be able to tell if the selection was made backward in the content when returned by PortableTextEditor.getSelection

This is needed in situations where the selection is made backward in the content, but we can only perform a task in the natural order (some for loop on text extractions or similar). By knowing that the selection is made backward, it's then just a matter of switching the anchor and focus points to have it in the natural order.

What to review

That the change looks good.

Testing

Should be covered by a lot of existing tests (see patch that updates them).

Notes for release

  • Added a backward property to the EditorSelection of the Portable Text Editor to tell if a selection was made backward in the content.

@skogsmaskin skogsmaskin requested review from a team and ninaandal and removed request for a team February 20, 2024 20:26
Copy link

vercel bot commented Feb 20, 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 Feb 21, 2024 10:47am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2024 10:47am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Feb 21, 2024 10:47am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Feb 20, 2024

Component Testing Report Updated Feb 21, 2024 10:51 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 13s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 33s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ❌ Failed (Inspect) 41s 14 0 1
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 58s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 19s 9 0 0

Copy link
Contributor

@pedrobonamin pedrobonamin left a comment

Choose a reason for hiding this comment

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

Is there any test case that we could add in which it covers the backward selection?
Or maybe update some of the current selections and add backward: true to be sure everything works in the same way even with the backward selection.

@skogsmaskin
Copy link
Member Author

Or maybe update some of the current selections and add backward: true to be sure everything works in the same way even with the backward selection.

This is a good idea. I will add it. I think the rest of the tests will make sure that the existing functionality still works as expected.

export type EditorSelection = {
anchor: EditorSelectionPoint
focus: EditorSelectionPoint
backward?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be a bit more clear with direction: "forward" | "backward" – what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be clearer, but then it would also have to be required imo.

The absence of "backward" means it's forward by default.

@skogsmaskin
Copy link
Member Author

skogsmaskin commented Feb 21, 2024

Added a new test that will test that getSelection returns the selection with the backward property set to true when the selection is set backward.

@skogsmaskin skogsmaskin added this pull request to the merge queue Feb 21, 2024
Merged via the queue into next with commit db8fd66 Feb 21, 2024
39 of 40 checks passed
@skogsmaskin skogsmaskin deleted the feat/pte-selection-backward branch February 21, 2024 10:58
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.

3 participants