getSelectionStart function
Returns the index of the first selected character in input
.
To workaround a bug in Chrome, returns null
for EmailInputElement and NumberInputElement on Chrome.
null
will also be returned for any input
that does not support selectionStart
.
Implementation
int? getSelectionStart(Element? input) {
if (input is TextAreaElement) {
return input.selectionStart;
} else if (input is InputElement && supportsSelectionRange(input)) {
final inputType = input.getAttribute('type');
if (browser.isChrome || browser.isFirefox) {
if (inputType == 'email' || inputType == 'number') {
// ignore: avoid_returning_null
return null;
}
}
return input.selectionStart;
}
// ignore: avoid_returning_null
return null;
}