<script>
let code = "function add(a, b) {\n\treturn a + b\n}"
let codeElement
let selections = []
let currentSelection = null
function updateSelection(event) {
currentSelection = {
start: codeElement.selectionStart,
end: codeElement.selectionEnd,
//text: code.substr(codeElement.selectionStart, codeElement.selectionEnd-codeElement.selectionStart)
}
}
function recordSelection() {
if (!currentSelection) returng
selections = [...selections, currentSelection]
}
function playbackSelections() {
selections.forEach((selection, index) => {
setTimeout(() => {
currentSelection = selection
codeElement.focus()
codeElement.setSelectionRange(selection.start, selection.end)
}, index * 1000)
})
// clear at the end
setTimeout(() => {
window.getSelection().empty()
currentSelection = null
}, selections.length * 1000)
}
</script>