DEV: removes unnecessary caret position code (#14665)

We don't support any browser needing this for very long: https://caniuse.com/?search=selectionStart

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.
This commit is contained in:
Joffrey JAFFEUX 2021-10-21 10:06:31 +02:00 committed by GitHub
parent a9d6b23802
commit 80ec6f09d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 29 deletions

View File

@ -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

View File

@ -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]);
};