Selection change event notes
var events = [
'touchstart',
'touchend',
'mousedown',
'mouseup',
'selectionchange',
'selectionchanged',
'selectstart',
];
var counts = events.reduce(function (counts, name) {
counts[name] = 0;
return counts;
}, {});
events.forEach(function (name) {
document.addEventListener(name, function () {
++counts[name];
console.log('%s triggered. count: %d', name, counts[name]);
});
});
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<script src="test.js"></script>
</body>
</html>
Notes on events that are fired during text selection in current desktop and mobile browsers.
Testing steps:
test.html
from local dev server and open on deviceDuring initial selection by long-pressing a word, Safari logs:
touchstart
selectionchange
touchend
During subsequent edits by dragging the start/end markers on the text, the selectionchange
event is fired each time the selection markers are adjusted. None of the other watched events are fired.
The selectstart
event is never fired.
During initial selection by long-pressing a word, these events were fired:
touchstart
selectstart
selectionchange
Adjusting the selection using the drag handles resulted in selectionchange
events but no further touch events.
During initial selection by long-pressing a word, these events were fired:
touchstart
Adjusting the selection using the drag handles resulted in no further touch, mouse or selection events.
During initial selection by long-pressing a word, these events were fired:
touchstart
selectstart
selectionchange
touchend
Adjusting the selection using the drag handles triggered selectionchange
events but no further touch events.