From 650c7dd1d346f5fe63e415a1714c159748930b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 12 Jul 2021 23:15:47 +0200 Subject: [PATCH] Avoid exception when trying to highlight hidden comment (e.g. if the comment is inside a node with 'display: none') Change-Id: I23a38fd877b1f9f1554962f7f08f7e2732d8f560 --- modules/controller.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/controller.js b/modules/controller.js index 83a9dc28d..a8f02ad7f 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -49,12 +49,15 @@ function highlight( comment ) { var baseRect = $highlight[ 0 ].getBoundingClientRect(); var rect = RangeFix.getBoundingClientRect( range ); - $highlight.css( { - 'margin-top': rect.top - baseRect.top - padding, - 'margin-left': rect.left - baseRect.left - padding, - width: rect.width + ( padding * 2 ), - height: rect.height + ( padding * 2 ) - } ); + // rect may be null if the range is in a detached or hidden node + if ( rect ) { + $highlight.css( { + 'margin-top': rect.top - baseRect.top - padding, + 'margin-left': rect.left - baseRect.left - padding, + width: rect.width + ( padding * 2 ), + height: rect.height + ( padding * 2 ) + } ); + } return $highlight; }