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(widget-string): fix cursor jumping to end of line #4607

Merged
merged 2 commits into from
Nov 26, 2020

Conversation

iansinnott
Copy link
Contributor

Closes #3578
Closes #4539

The approach taken here seems suboptimal since it's generally not necessary when writing React components to manually update cursor location. Please let me know if anyone has a better solution.

I did do some debugging to try to identify the root issue, but did not find the root cause.

The summary of what I found is this: It seems that nested widgets undergo additional rendering because they trigger a state update for their parent component as well as themself. For example, when editing the alt text of an image using the built-in image block element the updating markdown string causes the parent markdown widget to update.

Summary

This PR fixes the cursor problem described in detail in the linked issues. To summarize: Nested inputs within any collection would consistently force the cursor to the end of the line. Making nested inputs unusable for content editing.

"Nested" refers to text inputs within another widget—the alt text input element on the image widget for example.

Test plan

No automated tests have been created. I tested this by first running yarn start and then inserting an image into the markdown widget. I inserted an image into a post in the "Posts" collection of the test server, then typed in the "Alt text" field. The cursor remained where you would expect it to remain.

Although the URL may change, it looks something like: http://localhost:8080/#/collections/posts/entries/2020-11-20-post-number-19

@iansinnott iansinnott requested a review from a team November 19, 2020 01:42
@erezrokah erezrokah added the type: bug code to address defects in shipped code label Nov 19, 2020
@erezrokah erezrokah self-requested a review November 26, 2020 14:55
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks @iansinnott, while not the optimal solution - it does work very well.
An alternative is to have widgets manage their own state which is a bigger undertaking.
I pushed an additional commit to fix linting

@erezrokah erezrokah merged commit 1413d04 into decaporg:master Nov 26, 2020
@iansinnott
Copy link
Contributor Author

Thanks @erezrokah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
2 participants