<div id="entry-selection-save-restore"></div>
const app = Redactor('#entry-selection-save-restore');
// Save current selection (offset is stored on the editor instance).
app.saveSelection();
// ... your code that may move focus or change the DOM ...
// Restore the saved selection. The stored offset is cleared after restore.
app.restoreSelection();