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 sticky cursor resulting in reverse typing if the editable is not the activeElement in the document. #16066

Closed
wants to merge 2 commits into from

Conversation

urbanspr1nter
Copy link
Contributor

@urbanspr1nter urbanspr1nter commented Mar 21, 2024

This PR attempts to fix an issue with cases where "reverse typing" effect still occurs. This is caused by a selection not being updated when an input event occurs. The selection seems to not be updated because the document.activeElement in DOM is not the correct element.

There are cases where the editable visually looks focused, but in reality the active element is some other element as it may have stole focus while the editable was active at some point. This can be caused by a manual dispatch of a blur event for example.

We can actually simulate it like this:

setTimeout(() => { 
	const editable = document.querySelector("div[contenteditable=true]");
	editable.dispatchEvent(new FocusEvent("blur"));

	console.log("BLUR!")
}, 5000);

If the editable is currently in focus, but the blur happens later, the active element in the document is not updated properly, and can end up having a selection which is out of sync with the characters being rendered into the editable. (It just sticks and never moves forward).

An example:
274956696-3bd80cd7-cf19-4776-ab76-d1a026b4dd5f

Something like this can also be seen in the Safari web browser where a a button click can cause the issue to occur:
257527157-b3218162-a52b-453b-b0e5-9263952871ec
Source

After fix:
fix

Browsers tested on web (manual):

  • Google Chrome
  • Safari
  • Firefox

Suggested merge commit message (convention)

Type: (engine): Force the editable to be focused if the active element is not the editable when an input event occurs. Closes #15182, #14702 .


Additional information

For example – encountered issues, assumptions you had to make, other affected tickets, etc.

@urbanspr1nter urbanspr1nter changed the title [WIP] Reverse typing fix Fix sticky cursor resulting in reverse typing if the editable is not the activeElement in the document. Mar 21, 2024
@urbanspr1nter urbanspr1nter marked this pull request as ready for review March 21, 2024 04:24
@arkflpc arkflpc requested a review from niegowski March 21, 2024 09:23
@urbanspr1nter
Copy link
Contributor Author

Thoughts on this?

@Witoso
Copy link
Member

Witoso commented Apr 10, 2024

@urbanspr1nter thanks for the PR, and sorry for the late reply. A bit hectic down here 😊  @niegowski will soon take a look at a couple of problems regarding typing. We will take a look at this as well!

@Witoso
Copy link
Member

Witoso commented Apr 25, 2024

Hey @urbanspr1nter, we prepared a separate PR, as we are merging all typing improvements PRs to one branch. Thanks for the contribution, we used your solution but placed it in a slightly different place. Check #16267 for details. :)

@Witoso Witoso closed this Apr 25, 2024
@urbanspr1nter
Copy link
Contributor Author

Thanks! Of course, I'll always leave it to the experts. :)

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.

"Reverse typing" effect in some instances where selection may have been lost
2 participants