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

i/6053: The gravity of the selection should be overridden if a link was pasted for better typing experience #260

Closed
wants to merge 4 commits into from

Conversation

oleq
Copy link
Member

@oleq oleq commented Apr 17, 2020

Suggested merge commit message (convention)

Fix: The gravity of the selection should be overridden if a link was pasted for better typing experience. Closes ckeditor/ckeditor5#6053.

@coveralls
Copy link

coveralls commented Apr 17, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 7d63a37 on i/6053 into 0cea52f on master.

@jodator jodator self-assigned this Apr 20, 2020
@jodator jodator self-requested a review April 20, 2020 07:01
// Before paste:
//
// ↱
// []<$text linkHref="foo">link</$text>
Copy link
Contributor

@jodator jodator Apr 20, 2020

Choose a reason for hiding this comment

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

Edit: This is how link works in general. It is OK.

What should happen in a case below:

  1. Go inside link.
  2. Paste bolded text.
  3. Type.

What happens is that you type with but bold wasn't pasted):

@jodator
Copy link
Contributor

jodator commented Apr 20, 2020

@oleq I've found something like this:

  1. Paste link at the end of a text.
  2. Move cursor to highlight link using two-step caret movement.
  3. Start typing.

Expected: You should type with link.

Actual: Only the first character is typed with link. Subsequent are plain text.

Additional info: if you change selection to other place in the editor (other link, typing) and go back to the same position as in tested scenario the type with link works as expected.

Looks like minor issue to me if not something easy to spot.

Edit:

After step 1:

After step 2 (gravity is overridden):

After moving selection after other link (gravity is not overridden):

Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

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

I've found one behaviour inconsistency - looks like listening on change:range event is too narrow.


// Filter out the following case where a link is a pasted in the middle (or before) another link
// (different URLs, so they will not merge). In this (let's say weird) case, we can leave the gravity
// as it is because it would stick to the first link anyway.
Copy link
Contributor

Choose a reason for hiding this comment

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

I understood this as "it would stick to the first link ('foo') anyway" but the behaviour is that it sticks to the pasted link (also as shown on the sample below). I'd rephrase that comment to remove ambiguity.

}

// Skip automatic restore when the change is indirect.
// It means that e.g. if the change was external (collaboration) and the user had their
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs an ending ;)

}, { priority: 'low' } );

// Restore the selection gravity automatically as soon as the selection range changes.
selection.on( 'change:range', ( evt, data ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work in a case from a comment. The gravity change does not trigger this fixer (the ranges doesn't change) so you can't type with link.

model: 'bold',
view: 'b'
} );

model = editor.model;
view = editor.editing.view;
} );
} );

afterEach( () => {
editor.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be safer to wait for a promise to resolve.

I'm using async/await in test, but can be done with removing an element and then returning the editor.destroy() promise.

model: 'bold',
view: 'b'
} );

model = editor.model;
view = editor.editing.view;
} );
} );

afterEach( () => {
editor.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be safer to wait for a promise to resolve.

I'm using async/await in test, but can be done with removing an element and then returning the editor.destroy() promise.

@@ -73,8 +87,8 @@ describe( 'LinkEditing', () => {
} );

it( 'should be bound to th `linkHref` attribute (RTL)', () => {
return VirtualTestEditor
.create( {
return ClassicTestEditor
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be a follow-up but AFAICS the main beforeEach() editor was not destroyed and this looks like we could have two editors there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding element in tests and using ClassicTestEditor might create some memory leaks if multiple editors are created without removing previous one (from global beforeEach() ).

expect( model.document.selection.isGravityOverridden ).to.be.false;
} );

it( 'should restore gravity on the next change:range', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the test description is too technical ;) and will need to change. I'd go with the expected behaviour like when user move selection, or something similar.

sinon.assert.notCalled( spy );
} );

it( 'should not restore the gravity if the change:range was indirect (e.g. comming from the collaboration)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it( 'should not restore the gravity if the change:range was indirect (e.g. comming from the collaboration)', () => {
it( 'should not restore the gravity if the selection change was indirect (e.g. comming from the collaboration)', () => {

@@ -625,9 +824,20 @@ describe( 'LinkEditing', () => {
} );

describe( 'upcast converter', () => {
let element, editor;

beforeEach( () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Another nested beforeEach might be probably safe as it handles different editors. I don't like that there are two editors on the same page in this tests.

Again, this does not break now, but we need at least a follow-up for this whole file.

@oleq
Copy link
Member Author

oleq commented Apr 21, 2020

FYI we went with a better approach #261.

@oleq oleq closed this Apr 21, 2020
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.

Selection could be outside of the link after pasting
3 participants