Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active May 12, 2021 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/c7d8ed3d43dbb4a018fb392467fae365 to your computer and use it in GitHub Desktop.
Save nolanlawson/c7d8ed3d43dbb4a018fb392467fae365 to your computer and use it in GitHub Desktop.
Ranges issue repro
<!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