Sfoglia il codice sorgente

Added usage of parent node if node is a text node in Rect.

Maciej Bukowski 8 anni fa
parent
commit
148f895d63
1 ha cambiato i file con 13 aggiunte e 4 eliminazioni
  1. 13 4
      packages/ckeditor5-utils/src/dom/rect.js

+ 13 - 4
packages/ckeditor5-utils/src/dom/rect.js

@@ -7,6 +7,8 @@
  * @module utils/dom/rect
  */
 
+/* global Node */
+
 import isRange from './isrange';
 import isWindow from './iswindow';
 import isElement from '../lib/lodash/isElement';
@@ -361,12 +363,19 @@ export default class Rect {
 		// If there's no client rects for the Range, use parent container's bounding rect
 		// instead and adjust rect's width to simulate the actual geometry of such range.
 		// https://github.com/ckeditor/ckeditor5-utils/issues/153
+		// https://github.com/ckeditor/ckeditor5-ui/issues/317
 		else {
-			const startContainerRect = new Rect( range.startContainer.getBoundingClientRect() );
-			startContainerRect.right = startContainerRect.left;
-			startContainerRect.width = 0;
+			let startContainer = range.startContainer;
+
+			if ( startContainer.nodeType === Node.TEXT_NODE ) {
+				startContainer = startContainer.parentNode;
+			}
+
+			const rect = new Rect( startContainer.getBoundingClientRect() );
+			rect.right = rect.left;
+			rect.width = 0;
 
-			rects.push( startContainerRect );
+			rects.push( rect );
 		}
 
 		return rects;