Fix long range comment selection on Firefox

The shadow-selection-polyfill only returns the first range for
Firefox, bypassing our range-merge logic that gives us the
endpoints of the selection. This change makes gr-diff only use
the polyfill for Safari.

(cherry-picked from https://gerrit-review.googlesource.com/c/gerrit/+/296582)
Change-Id: I3a33264dc804a72b0456f5224199f0844343c166
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
index 1e7ffb4..06ffabc 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
@@ -337,11 +337,13 @@
   _getShadowOrDocumentSelection() {
     // When using native shadow DOM, the selection returned by
     // document.getSelection() cannot reference the actual DOM elements making
-    // up the diff, because they are in the shadow DOM of the gr-diff element.
-    // This takes the shadow DOM selection if one exists.
+    // up the diff in Safari because they are in the shadow DOM of the gr-diff
+    // element. This takes the shadow DOM selection if one exists.
     return this.root.getSelection ?
       this.root.getSelection() :
-      shadow.getRange(this.root);
+      this._isSafari() ?
+        shadow.getRange(this.root) :
+        document.getSelection();
   }
 
   _observeNodes() {
@@ -984,6 +986,13 @@
       }
     }, 0);
   }
+
+  _isSafari() {
+    return (
+      /^((?!chrome|android).)*safari/i.test(navigator.userAgent) ||
+      (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
+    );
+  }
 }
 
 customElements.define(GrDiff.is, GrDiff);