Explorar o código

Fix: Skip native DOM selection change in case of subsequent requests 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).
Marek Lewandowski %!s(int64=6) %!d(string=hai) anos
pai
achega
7cfd365743
Modificáronse 1 ficheiros con 15 adicións e 0 borrados
  1. 15 0
      packages/ckeditor5-engine/src/view/renderer.js

+ 15 - 0
packages/ckeditor5-engine/src/view/renderer.js

@@ -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.
@@ -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.
 	 *