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

Commit 3f059a7

Browse files
authored
Merge pull request #1246 from ckeditor/t/ckeditor5/752
Fix: The fake selection container will not leak into the viewport. Closes ckeditor/ckeditor5#752.
2 parents b527d7f + dc8cdce commit 3f059a7

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/view/renderer.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -567,35 +567,42 @@ export default class Renderer {
567567
*/
568568
_updateFakeSelection( domRoot ) {
569569
const domDocument = domRoot.ownerDocument;
570+
let container = this._fakeSelectionContainer;
570571

571572
// Create fake selection container if one does not exist.
572-
if ( !this._fakeSelectionContainer ) {
573-
this._fakeSelectionContainer = domDocument.createElement( 'div' );
574-
this._fakeSelectionContainer.style.position = 'fixed';
575-
this._fakeSelectionContainer.style.top = 0;
576-
this._fakeSelectionContainer.style.left = '-9999px';
577-
this._fakeSelectionContainer.appendChild( domDocument.createTextNode( '\u00A0' ) );
573+
if ( !container ) {
574+
this._fakeSelectionContainer = container = domDocument.createElement( 'div' );
575+
576+
Object.assign( container.style, {
577+
position: 'fixed',
578+
top: 0,
579+
left: '-9999px',
580+
// See https://github.com/ckeditor/ckeditor5/issues/752.
581+
width: '42px'
582+
} );
583+
584+
// Fill it with a text node so we can update it later.
585+
container.appendChild( domDocument.createTextNode( '\u00A0' ) );
578586
}
579587

580588
// Add fake container if not already added.
581-
if ( !this._fakeSelectionContainer.parentElement ) {
582-
domRoot.appendChild( this._fakeSelectionContainer );
589+
if ( !container.parentElement ) {
590+
domRoot.appendChild( container );
583591
}
584592

585593
// Update contents.
586-
const content = this.selection.fakeSelectionLabel || '\u00A0';
587-
this._fakeSelectionContainer.firstChild.data = content;
594+
container.firstChild.data = this.selection.fakeSelectionLabel || '\u00A0';
588595

589596
// Update selection.
590597
const domSelection = domDocument.getSelection();
591-
domSelection.removeAllRanges();
592-
593598
const domRange = domDocument.createRange();
594-
domRange.selectNodeContents( this._fakeSelectionContainer );
599+
600+
domSelection.removeAllRanges();
601+
domRange.selectNodeContents( container );
595602
domSelection.addRange( domRange );
596603

597604
// Bind fake selection container with current selection.
598-
this.domConverter.bindFakeSelection( this._fakeSelectionContainer, this.selection );
605+
this.domConverter.bindFakeSelection( container, this.selection );
599606
}
600607

601608
/**

0 commit comments

Comments
 (0)