From e1fc5e03bb925563f42778e5b8ed81f88442b1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Thu, 20 Apr 2017 14:44:58 +0200 Subject: [PATCH] Internal: Fixed a test and simplified jumpOverInlineFiller() implementation. See #925. --- src/view/filler.js | 12 ++++-------- tests/view/document/jumpoverinlinefiller.js | 13 +++++++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/view/filler.js b/src/view/filler.js index 21a392dc9..1b633a8bc 100644 --- a/src/view/filler.js +++ b/src/view/filler.js @@ -3,7 +3,7 @@ * For licensing, see LICENSE.md. */ -/* globals window, Range, Text */ +/* globals window, Text */ import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard'; @@ -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. @@ -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(); @@ -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 ); } } } diff --git a/tests/view/document/jumpoverinlinefiller.js b/tests/view/document/jumpoverinlinefiller.js index afbeb914c..30b8e9b25 100644 --- a/tests/view/document/jumpoverinlinefiller.js +++ b/tests/view/document/jumpoverinlinefiller.js @@ -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^FILLER", but Safari + // will render it on "foo^...". 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; } );