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: stop cursor jump with ampersands #139

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

tbui17
Copy link

@tbui17 tbui17 commented Feb 6, 2025

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.

  • Added handling for & in html normalization
  • Unified export style with current codebase (no default exports)
  • Removed dependency react-contenteditable and installed latest versions of its dependencies

This PR still needs tests and might need end-to-end testing as implementation is dispatched dynamically depending on browser.

Copy link

vercel bot commented Feb 6, 2025

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

Name Status Preview Comments Updated (UTC)
open-resume ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 6, 2025 7:16am

@tbui17 tbui17 changed the title fix: cursor jump with ampersands fix: stop cursor jump with ampersands Feb 6, 2025
a-sync added a commit to a-sync/my-open-resume that referenced this pull request Feb 6, 2025
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.

Bullet point text areas containing ampersands shift cursor to the end when editing
1 participant