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

Edge loses selection position when focused the first time #1923

Merged
merged 5 commits into from
Aug 26, 2019
Merged

Conversation

Comandeer
Copy link
Member

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

It's just a dirty hack for Edge. I've added check in domFix to allow reselection in Edge only if the editor was previously focused. To check it I use editor._.previousActive.

The real source of the issue is buried deep in our selection. It seems that call to selection.removeAllRanges somehow prevents Edge from changing selection. The procedure for clicking the first time into editable area is:

  • treat focus event as clicking at the beginning of the content
  • then treat the click as a separate selection change.

Our domFix method interrupts this procedure and changes it to:

  • treat focus event as clicking at the beginning of the content
  • add missing bogus brs and reselect the current selection
  • then treat the click as a separate selection change.

It works this way in IE. However Edge seems to stop after reselecting and does not change selection to the place of the click. But how it is connected with removing ranges – I don't really know.

As this issue is visible only on the first focus and researching our whole flow of focusing and selecting could take very long, I decided to apply some minimal hack instead.

Closes #504.

@f1ames
Copy link
Contributor

f1ames commented Aug 19, 2019

Rebased onto latest major.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Looks good, just two minor things to address.

tests/core/editable/manual/edgefirstfocus.md Outdated Show resolved Hide resolved
tests/core/editable/domfix3.js Show resolved Hide resolved
@Comandeer Comandeer self-assigned this Aug 23, 2019
@Comandeer Comandeer requested a review from f1ames August 24, 2019 15:15
@f1ames f1ames self-assigned this Aug 26, 2019
@f1ames
Copy link
Contributor

f1ames commented Aug 26, 2019

Rebased onto latest major.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

LGTM 👍

tests/core/editable/domfix3.js Show resolved Hide resolved
@f1ames f1ames merged commit 12fa86c into major Aug 26, 2019
@CKEditorBot CKEditorBot deleted the t/504 branch August 26, 2019 08:42
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.

Editor viewport is scrolled back to the top when focusing editor for the first time
2 participants