Last active
May 12, 2021 23:14
-
-
Save nolanlawson/c7d8ed3d43dbb4a018fb392467fae365 to your computer and use it in GitHub Desktop.
Ranges issue repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Ranges issue repro</title> | |
</head> | |
<body> | |
<h1>Ranges issue repro</h1> | |
<label> | |
Click and then type here: | |
<input type="text"> | |
</label> | |
<script> | |
document.querySelector('input').addEventListener('click', function () { | |
var selection = getSelection() | |
var ranges = [] | |
for (var i = 0; i < selection.rangeCount; i++) { | |
ranges.push(selection.getRangeAt(i)) | |
} | |
selection.removeAllRanges() | |
ranges.forEach(function (range) { | |
selection.addRange(range) | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment