export function insertText({text,cursor}) { const isFirefox = () => { const userAgent = window.navigator.userAgent.toLowerCase(); if (userAgent.indexOf('firefox') != -1) { return true; } return false; }; cursor.focus(); if (isFirefox()) { const start = cursor.selectionStart; // in this case maybe 0 cursor.setRangeText(text); cursor.selectionStart = cursor.selectionEnd = start + text.length; const uiEvent = document.createEvent('UIEvent'); uiEvent.initEvent('input', true, false); cursor.dispatchEvent(uiEvent); } else { document.execCommand('insertText', false, text); } }