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

Commit

Permalink
Internal: Fixed a test and simplified jumpOverInlineFiller() implemen…
Browse files Browse the repository at this point in the history
…tation. See #925.
  • Loading branch information
Reinmar committed Apr 20, 2017
1 parent 6701c4b commit e1fc5e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/view/filler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

/* globals window, Range, Text */
/* globals window, Text */

import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';

Expand Down Expand Up @@ -143,7 +143,7 @@ export function isBlockFiller( domNode, blockFiller ) {
}

/**
* Assign key observer which move cursor from the end of the inline filler to the begging of it when
* Assign key observer which move cursor from the end of the inline filler to the beginning of it when
* the left arrow is pressed, so the filler does not break navigation.
*
* @param {module:engine/view/document~Document} document Document instance we should inject quirks handling on.
Expand All @@ -152,7 +152,7 @@ export function injectQuirksHandling( document ) {
document.on( 'keydown', jumpOverInlineFiller );
}

// Move cursor from the end of the inline filler to the begging of it when, so the filler does not break navigation.
// Move cursor from the end of the inline filler to the beginning of it when, so the filler does not break navigation.
function jumpOverInlineFiller( evt, data ) {
if ( data.keyCode == keyCodes.arrowleft ) {
const domSelection = data.domTarget.ownerDocument.defaultView.getSelection();
Expand All @@ -162,11 +162,7 @@ function jumpOverInlineFiller( evt, data ) {
const domOffset = domSelection.getRangeAt( 0 ).startOffset;

if ( startsWithFiller( domParent ) && domOffset <= INLINE_FILLER_LENGTH ) {
const domRange = new Range();
domRange.setStart( domParent, 0 );
domRange.collapse( true );
domSelection.removeAllRanges();
domSelection.addRange( domRange );
domSelection.collapse( domParent, 0 );
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions tests/view/document/jumpoverinlinefiller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ describe( 'Document', () => {

const domSelection = document.getSelection();

expect( domSelection.anchorNode.data ).to.equal( 'foo' );
expect( domSelection.anchorOffset ).to.equal( 3 );
// There's a problem now. We expect that the selection was moved to "foo<b>^FILLER</b>", but Safari
// will render it on "foo^<b>...". Both options are correct.

if ( domSelection.anchorNode.data == 'foo' ) {
expect( domSelection.anchorNode.data ).to.equal( 'foo' );
expect( domSelection.anchorOffset ).to.equal( 3 );
} else {
expect( isInlineFiller( domSelection.anchorNode ) ).to.be.true;
expect( domSelection.anchorOffset ).to.equal( 0 );
}

expect( domSelection.isCollapsed ).to.be.true;
} );

Expand Down

0 comments on commit e1fc5e0

Please sign in to comment.