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

Update Selection #709

Merged
merged 2 commits into from
Jan 9, 2025
Merged

Update Selection #709

merged 2 commits into from
Jan 9, 2025

Conversation

coreyogburn
Copy link
Contributor

When clicking on a config value, we hide the text-area and invisibly swap out to a different text-area. It's almost invisible except that the focus isn't maintained: the user focused the old element but not the new one.

Simply adding a call to .focus() puts the cursor in a different place than where the user clicked. This isn't how text controls work and can break a user's flow.

The selection cursor isn't updated to the click location in the focus event handler so it was refactored to be a click handler. In the edit event that fires, the scroll position and selection range are taken from the old input and on next tick applied to the new input. This makes the control swapping truly invisible.

You still have to focus the text-area before the resize handle will be available though.

When clicking on a config value, we hide the text-area and invisibly swap out to a different text-area. It's almost invisible except that the focus isn't maintained: the user focused the old element but not the new one.

Simply adding a call to .focus() puts the cursor in a different place than where the user clicked. This isn't how text controls work and can break a user's flow.

The selection cursor isn't updated to the click location in the focus event handler so it was refactored to be a click handler. In the edit event that fires, the scroll position and selection range are taken from the old input and on next tick applied to the new input. This makes the control swapping truly invisible.

You still have to focus the text-area before the resize handle will be available though.
Tabbing to the control wasn't giving it focus. Reverted the event back to focus and then wrapped the event body in a `setTimeout([event body], 1)` so it executes after the click event sets the selection range.

Now it works for node specific values as well by adapting the selector to the nodeId parameter.

Tabbing to the control puts the cursor at the end.

Clicking on the control puts the cursor where the user clicks.

Highlighting text in the control highlights the same text.

Methodology used: We setTimeout(..., 1) to let the click event finish so the cursor location is accurate. After that, we change our form variables normally. Then we collect scroll and caret information. We wait one tick for the form changes we just made to propogate through the UI and then we set the scroll and caret information on the new text-area.
@coreyogburn coreyogburn merged commit cbe92cb into 2.4/dev Jan 9, 2025
3 checks passed
@coreyogburn coreyogburn deleted the cogburn/settings-click-fix branch January 9, 2025 22:48
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants