DEV: removes unnecessary caret position code (#14665)

DEV: removes unnecessary caret position code (#14665)

We don’t support any browser needing this for very long: "selectionStart" | Can I use... Support tables for HTML5, CSS3, etc

I’m keeping some protection so It doesn’t crash but ultimately element.selectionStart should be enough.

Im not removing this in the commit, but the caret_position.js file seems barely used.

diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.js
index 654eaeb..980ea24 100644
--- a/app/assets/javascripts/discourse/app/lib/utilities.js
+++ b/app/assets/javascripts/discourse/app/lib/utilities.js
@@ -224,24 +224,7 @@ export function caretRowCol(el) {
 
 // Determine the position of the caret in an element
 export function caretPosition(el) {
-  let r, rc, re;
-  if (el.selectionStart) {
-    return el.selectionStart;
-  }
-  if (document.selection) {
-    el.focus();
-    r = document.selection.createRange();
-    if (!r) {
-      return 0;
-    }
-
-    re = el.createTextRange();
-    rc = re.duplicate();
-    re.moveToBookmark(r.getBookmark());
-    rc.setEndPoint("EndToStart", re);
-    return rc.text.length;
-  }
-  return 0;
+  return el?.selectionStart || 0;
 }
 
 // Set the caret's position
diff --git a/vendor/assets/javascripts/caret_position.js b/vendor/assets/javascripts/caret_position.js
index 2393c6f..3a7ca2c 100644
--- a/vendor/assets/javascripts/caret_position.js
+++ b/vendor/assets/javascripts/caret_position.js
@@ -6,22 +6,11 @@ var clone = null;
 
 $.fn.caret = function(elem) {
   var getCaret = function(el) {
-    var r, rc, re;
     if (el.selectionStart) {
       return el.selectionStart;
-    } else if (document.selection) {
-      el.focus();
-      r = document.selection.createRange();
-      if (!r) return 0;
-      re = el.createTextRange();
-      rc = re.duplicate();
-      re.moveToBookmark(r.getBookmark());
-      rc.setEndPoint("EndToStart", re);
-      return rc.text.length;
     }
     return 0;
   };
-
   return getCaret(elem || this[0]);
 };
 

GitHub sha: 80ec6f09d375f4c5095b9f87fadeb7f733d29fef

This commit appears in #14665 which was approved by eviltrout and pmusaraj. It was merged by jjaffeux.