From fb13235a86ef40a968f3836e50569a836de01905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20Van=C2=A0Dorpe?= Date: Sat, 5 May 2018 15:33:00 +0200 Subject: [PATCH] Fix caretRangeFromPoint for Firefox (#6598) --- utils/dom.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/dom.js b/utils/dom.js index bedf98ba6c5feb..f0dbeb5c5ae8f8 100644 --- a/utils/dom.js +++ b/utils/dom.js @@ -251,6 +251,13 @@ function caretRangeFromPoint( doc, x, y ) { } const point = doc.caretPositionFromPoint( x, y ); + + // If x or y are negative, outside viewport, or there is no text entry node. + // https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint + if ( ! point ) { + return null; + } + const range = doc.createRange(); range.setStart( point.offsetNode, point.offset );