HTMLInputElement.selectionStart, selectionEnd, and selectionDirection javascripttte bu fonksiyonlara bakarsan olayı halledersin. prepend ve append de biliyorsundur :)
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange