void (@NotNull Editor editor, int restoredCaretOffset, @NotNull Runnable restoreSelection) { //move to old offset Runnable runnable = () -> { editor.getCaretModel().moveToOffset(restoredCaretOffset); restoreSelection.run(); }; LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup != null && lookup.getLookupStart() <= restoredCaretOffset) { lookup.setLookupFocusDegree(LookupFocusDegree.UNFOCUSED); lookup.performGuardedChange(runnable); } else { runnable.run(); } }