mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
a9d6b23802
commit
80ec6f09d3
@ -224,24 +224,7 @@ export function caretRowCol(el) {
|
|||||||
|
|
||||||
// Determine the position of the caret in an element
|
// Determine the position of the caret in an element
|
||||||
export function caretPosition(el) {
|
export function caretPosition(el) {
|
||||||
let r, rc, re;
|
return el?.selectionStart || 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the caret's position
|
// Set the caret's position
|
||||||
|
11
vendor/assets/javascripts/caret_position.js
vendored
11
vendor/assets/javascripts/caret_position.js
vendored
@ -6,22 +6,11 @@ var clone = null;
|
|||||||
|
|
||||||
$.fn.caret = function(elem) {
|
$.fn.caret = function(elem) {
|
||||||
var getCaret = function(el) {
|
var getCaret = function(el) {
|
||||||
var r, rc, re;
|
|
||||||
if (el.selectionStart) {
|
if (el.selectionStart) {
|
||||||
return 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 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
return getCaret(elem || this[0]);
|
return getCaret(elem || this[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user