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 #172 from ckeditor/t/72
Browse files Browse the repository at this point in the history
Feature: Added two-step caret movement for links. See #72.
  • Loading branch information
Reinmar authored Feb 27, 2018
2 parents 0641978 + 74af1cf commit 985bb40
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isLinkElement } from './utils';
import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';

import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
import bindTwoStepCaretToAttribute from '@ckeditor/ckeditor5-engine/src/utils/bindtwostepcarettoattribute';

import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import LinkFormView from './ui/linkformview';
Expand Down Expand Up @@ -82,6 +83,9 @@ export default class Link extends Plugin {

// Attach lifecycle actions to the the balloon.
this._enableUserBalloonInteractions();

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

/**
Expand Down
22 changes: 21 additions & 1 deletion tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe( 'Link', () => {
expect( editor.plugins.get( ContextualBalloon ) ).to.be.instanceOf( ContextualBalloon );
} );

describe( 'init', () => {
describe( 'init()', () => {
it( 'should register click observer', () => {
expect( editor.editing.view.getObserver( ClickObserver ) ).to.be.instanceOf( ClickObserver );
} );
Expand All @@ -82,6 +82,26 @@ describe( 'Link', () => {
expect( formView ).to.be.instanceOf( LinkFormView );
} );

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.

// 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 land here not as a result of `keydown`.
expect( editor.model.document.selection.isGravityOverridden ).to.false;

// 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;
} );

describe( 'link toolbar button', () => {
it( 'should be registered', () => {
expect( linkButton ).to.be.instanceOf( ButtonView );
Expand Down

0 comments on commit 985bb40

Please sign in to comment.