-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rect.getDomRangeRects doesn't support ranges inside the text nodes #4969
Comments
And what's the actual test case? How can a user reproduce this? |
I suppose the issue is about this line. What is interesting, though, is why the algorithm fell into this condition. It (most certainly) shouldn't unless you're using Safari. Are you sure the range returned by |
This happened in tests, so that might've been some special, not really realistic case. But yes, it might happen in Safari. |
Anyway, let's fix this quickly because we simply might've missed cases when it occurs when testing manually. |
As it turned out in a F2F communication with @ma2ciek, the test that was the source of the issue didn't add the editor UI ( What we can do now is to:
|
Oh, so the error is that text nodes didn't have bounding client rect because they weren't added to DOM? This is a bug in a test obviously, but I think that we need to secure the scroll* methods anyway. Throwing errors from such tools will not be very useful (especially for tests). I'd rather make them log a warning and abort. WDYT? |
We can check this in the diff --git a/src/dom/rect.js b/src/dom/rect.js
index 49bc2aa..060baa1 100644
--- a/src/dom/rect.js
+++ b/src/dom/rect.js
@@ -11,6 +11,7 @@ import global from './global';
import isRange from './isrange';
import isElement from '../lib/lodash/isElement';
import getBorderWidths from './getborderwidths';
+import log from '../log';
/**
* A helper class representing a `ClientRect` object, e.g. value returned by
@@ -60,6 +61,19 @@ export default class Rect {
enumerable: false
} );
+ if ( isElement( source ) || isRange( source ) ) {
+ const relatedNode = isRange( source ) ? source.startContainer : source;
+
+ if ( !relatedNode.ownerDocument.body.contains( relatedNode ) ) {
+ /**
+ * TODO
+ *
+ * @error rect-source-not-in-dom
+ */
+ log.warn( 'rect-source-not-in-dom: The source of this rect does not belong to any rendered DOM tree.', source );
+ }
+ }
+
if ( isElement( source ) ) {
copyRectProperties( this, source.getBoundingClientRect() );
} else if ( isRange( source ) ) {
|
I'd avoid checking if the DOM contains anything. That will be another problem when adding support for iframes. Can't we handle situation when there's a problem with getClientBoundingRect? We might log a warning immediately and set rect to 0,0,0,0 |
|
That's true. Sorry, I was prejudiced regarding checking that :D. So, it seems ok. But will the change you proposed above prevent the code from throwing? Or do we need something more anyway? |
It will throw. But the warning will give you the reason why. Or... we can throw our own error instead of log.warn. |
Hm... I initially thought about setting the rect to 0,0,0,0 so there's no crash and warning just in case (so you know that you did something incorrect). Overengineered? Is it better to just throw our error? |
A rect with |
…L element or a DOM range not belonging to a rendered DOM tree. Closes #178.
…tility warnings (see: ckeditor/ckeditor5-utils#178).
…tility warnings (see: ckeditor/ckeditor5-utils#178).
Internal: A warning should show up when a Rect instance is for an HTML element or a DOM range not belonging to a rendered DOM tree. Closes #178.
…utility warnings (see: ckeditor/ckeditor5-utils#178).
…tility warnings (see: ckeditor/ckeditor5-utils#178).
…t utility warnings (see: ckeditor/ckeditor5-utils#178).
Running
documentView.scrollToTheSelection
when selection is inside some text nodes throws the following Error:Error: Uncaught TypeError: range.startContainer.getBoundingClientRect is not a function.
The text was updated successfully, but these errors were encountered: