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

Commit

Permalink
Fix: Skip native DOM selection change in case of subsequent requests …
Browse files Browse the repository at this point in the history
…for the same fake selection.

Constantly changing the selection poses a severe bottleneck for browser rendering, observed in the image resize feature (see ckeditor/ckeditor5-image#310).
  • Loading branch information
mlewand committed Sep 6, 2019
1 parent ab87679 commit 1d300d5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ export default class Renderer {

if ( !container.parentElement || container.parentElement != domRoot ) {
domRoot.appendChild( container );
} else if ( !this._fakeSelectionNeedsUpdate( domRoot ) ) {
return;
}

// Update contents.
Expand Down Expand Up @@ -792,6 +794,19 @@ export default class Renderer {
return true;
}

/**
* Checks whether the fake selection needs to be updated.
*
* @private
* @param {HTMLElement} domRoot A valid DOM root where a new fake selection container should be added.
* @returns {Boolean}
*/
_fakeSelectionNeedsUpdate( domRoot ) {
const container = this._fakeSelectionContainer;

return !container || container.parentElement != domRoot || container.textContent !== this.selection.fakeSelectionLabel;
}

/**
* Removes the DOM selection.
*
Expand Down

0 comments on commit 1d300d5

Please sign in to comment.