fix: stop cursor jump with ampersands #139
Draft
+169
−25
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.
fixes #138
The component depends on https://github.com/lovasoa/react-contenteditable for bullet list text area with automatic HTML stripping when pasting. Unfortunately, the library looks like it is no longer being maintained. It is a small library, so the code was just copied over with necessary changes.
When the component re-renders, the cursor position will reset to the end of the last character. The component has internal checks for preventing re-renders from user-initiated changes. User-initiated changes will not create any changes in the next prop during
shouldComponentUpdate
, while programmatic changes do. When the HTML strings of the component and the next prop are compared, they first need to be normalized. The previous implementation did not handle ampersand characters during normalization, which meant the HTML strings would always be different, causing a re-render on every input when there was an ampersand character in user-provided text. This change simply adds handling for the ampersand case in normalization.&
in html normalizationreact-contenteditable
and installed latest versions of its dependenciesThis PR still needs tests and might need end-to-end testing as implementation is dispatched dynamically depending on browser.