Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

t/1439: Firefox should visually move the caret to the new line after a soft break #1582

Merged
merged 7 commits into from
Oct 26, 2018

Conversation

oleq
Copy link
Member

@oleq oleq commented Oct 18, 2018

Suggested merge commit message (convention)

Fix: Firefox should visually move the caret to the new line after a soft break. Closes ckeditor/ckeditor5#4363.


Additional information

In a F2F talk with @scofalik we decided to keep browser quirks in the engine rather in features (like ShiftEnterCommand).

The entire fix is just domSelection.addRange( domSelection.getRangeAt( 0 ) ); BTW ;-)

@oleq oleq requested review from f1ames and scofalik October 18, 2018 15:10
@@ -1714,6 +1715,74 @@ describe( 'Renderer', () => {
expect( domRoot.innerHTML ).to.equal( '<ul><li>Foo<ul><li><b>Bar</b><i>Baz</i></li></ul></li></ul>' );
} );

// #1439
it( 'should force–refresh the selection in FF after a soft break to nudge the caret (non-gecko)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the test name be something like "it should not force-refresh the selection after a soft break in non-gecko browsers" and the other one negated?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I am not that sure if we need such a test and if we can test it properly. I mean, the test works but checking if addRange was called is a bit dangerous. If we ever use it in the normal selection setting process the test will start failing and we will have to remove it anyway. I would be fine with manual test only, I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @scofalik on changing test names to something like it should not force-refresh the selection after a soft break in non-gecko browsers and it should force-refresh the selection after a soft break in gecko browsers.

As for not having unit test, we probably need some to have 100% cc (unless this code is already covered by some not directly related tests). Still it is a visual issue so can't be really tested reasonable with unit test. Anyway, I'm ok with leaving the test as is or just removing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed the tests. I'm for keeping them, well at least for the CC.

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.

Apart from some small changes in unit tests, it looks good.

@@ -1714,6 +1715,74 @@ describe( 'Renderer', () => {
expect( domRoot.innerHTML ).to.equal( '<ul><li>Foo<ul><li><b>Bar</b><i>Baz</i></li></ul></li></ul>' );
} );

// #1439
it( 'should force–refresh the selection in FF after a soft break to nudge the caret (non-gecko)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @scofalik on changing test names to something like it should not force-refresh the selection after a soft break in non-gecko browsers and it should force-refresh the selection after a soft break in gecko browsers.

As for not having unit test, we probably need some to have 100% cc (unless this code is already covered by some not directly related tests). Still it is a visual issue so can't be really tested reasonable with unit test. Anyway, I'm ok with leaving the test as is or just removing it.

// To stay on the safe side, the fix being as specific as possible, it targets only the
// selection which is at the very end of the element and preceded by <br />.
if ( childAtOffset && childAtOffset.tagName == 'BR' ) {
domSelection.addRange( domSelection.getRangeAt( 0 ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a concern about domSelection.addRange if adding another range will not result in selection having two ranges (as they are the same it doesn't makes sense probably) but it seems there is one range after this call 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I was also worried about that but as you said, there's only one range after this call.

Anyway, let's make sure I didn't break FF with this branch. @Mgsy, can you help us?

@oleq oleq requested a review from Mgsy October 24, 2018 14:27
@coveralls
Copy link

coveralls commented Oct 24, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 0342eba on t/1439 into 5d26bc3 on master.

Copy link
Member

@Mgsy Mgsy left a comment

Choose a reason for hiding this comment

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

Works fine 👌

@Reinmar
Copy link
Member

Reinmar commented Oct 25, 2018

@oleq could you resolve CI and coverage issues?

@oleq
Copy link
Member Author

oleq commented Oct 26, 2018

I think the coverage decreased because this PR requires a branch in the utils, which hadn't been merged yet at that point.

It's 100% now.

// which happens a lot when using the soft line break, the browser fails to (visually) move the
// caret to the new line. A quick fix is as simple as force–refreshing the selection with the same range.
if ( env.isGecko ) {
const parent = focus.parent;
Copy link
Member

Choose a reason for hiding this comment

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

I'll move the entire body of this condition to another function because it looks bad that there's a return inside it. What if someone would like to add another such hack after this one? We'll need to refactor it anyway.

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.

I see tests were updated as requested and the rest of the code is fine with me 👍

@Reinmar Reinmar merged commit 80392ad into master Oct 26, 2018
@Reinmar Reinmar deleted the t/1439 branch October 26, 2018 13:00
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.

[FF] Caret is rendered before a <br> despite the model selection being after it
6 participants