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

Commit

Permalink
Merge pull request #244 from ckeditor/t/ckeditor5/1151
Browse files Browse the repository at this point in the history
Other: Passed editor content direction to the `bindTwoStepCaretToAttribute()` helper in the `LinkEditing` plugin. See ckeditor/ckeditor5#1151.
  • Loading branch information
Reinmar authored Aug 12, 2019
2 parents 14e5803 + dbe6631 commit 73bf132
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/linkediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class LinkEditing extends Plugin {
*/
init() {
const editor = this.editor;
const locale = editor.locale;

// Allow link attribute on all inline nodes.
editor.model.schema.extend( '$text', { allowAttributes: 'linkHref' } );
Expand Down Expand Up @@ -83,7 +84,13 @@ export default class LinkEditing extends Plugin {
this._enableManualDecorators( linkDecorators.filter( item => item.mode === DECORATOR_MANUAL ) );

// Enable two-step caret movement for `linkHref` attribute.
bindTwoStepCaretToAttribute( editor.editing.view, editor.model, this, 'linkHref' );
bindTwoStepCaretToAttribute( {
view: editor.editing.view,
model: editor.model,
emitter: this,
attribute: 'linkHref',
locale
} );

// Setup highlight over selected link.
this._setupLinkHighlight();
Expand Down
60 changes: 46 additions & 14 deletions tests/linkediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,56 @@ describe( 'LinkEditing', () => {
expect( model.schema.checkAttribute( [ '$block' ], 'linkHref' ) ).to.be.false;
} );

it( 'should bind two-step caret movement to `linkHref` attribute', () => {
// Let's check only the minimum to not duplicated `bindTwoStepCaretToAttribute()` tests.
// Testing minimum is better then testing using spies that might give false positive results.
// Let's check only the minimum to not duplicate `bindTwoStepCaretToAttribute()` tests.
// Testing minimum is better than testing using spies that might give false positive results.
describe( 'two-step caret movement', () => {
it( 'should be bound to th `linkHref` attribute (LTR)', () => {
// Put selection before the link element.
setModelData( editor.model, '<paragraph>foo[]<$text linkHref="url">b</$text>ar</paragraph>' );

// The selection's gravity is not overridden because selection landed here not because of `keydown`.
expect( editor.model.document.selection.isGravityOverridden ).to.false;

// So let's simulate the `keydown` event.
editor.editing.view.document.fire( 'keydown', {
keyCode: keyCodes.arrowright,
preventDefault: () => {},
domTarget: document.body
} );

// Put selection before the link element.
setModelData( editor.model, '<paragraph>foo[]<$text linkHref="url">b</$text>ar</paragraph>' );
expect( editor.model.document.selection.isGravityOverridden ).to.true;
} );

// The selection's gravity is not overridden because selection land here not as a result of `keydown`.
expect( editor.model.document.selection.isGravityOverridden ).to.false;
it( 'should be bound to th `linkHref` attribute (RTL)', () => {
return VirtualTestEditor
.create( {
plugins: [ Paragraph, LinkEditing, Enter ],
language: {
content: 'ar'
}
} )
.then( editor => {
model = editor.model;
view = editor.editing.view;

// Put selection before the link element.
setModelData( editor.model, '<paragraph>foo[]<$text linkHref="url">b</$text>ar</paragraph>' );

// The selection's gravity is not overridden because selection landed here not because of `keydown`.
expect( editor.model.document.selection.isGravityOverridden ).to.false;

// So let's simulate the `keydown` event.
editor.editing.view.document.fire( 'keydown', {
keyCode: keyCodes.arrowleft,
preventDefault: () => {},
domTarget: document.body
} );

// So let's simulate `keydown` event.
editor.editing.view.document.fire( 'keydown', {
keyCode: keyCodes.arrowright,
preventDefault: () => {},
domTarget: document.body
} );
expect( editor.model.document.selection.isGravityOverridden ).to.true;

expect( editor.model.document.selection.isGravityOverridden ).to.true;
return editor.destroy();
} );
} );
} );

describe( 'command', () => {
Expand Down

0 comments on commit 73bf132

Please sign in to comment.