The problem is that the cursor is not positioned in front of the text, but it is returned to the beginning. with the 'focus' event that does not happen, but I want it to work with the 'keyup' event
let textarea = document.querySelector('#textarea')
function funcion()
{
textarea.innerHTML = textarea.innerText.replace(/@[a-zA-Z0-9_]+/gi, '<a href="https://www.dominio.com/?user=$&">$&</a>')
}
textarea.addEventListener('keyup', funcion)
<div id="textarea" contenteditable="true" style="height: 100px; padding: 10px; border: 1px solid #000"></div>