WatchingInsertionContext (@NotNull OffsetsInFile topLevelOffsets, LookupElement item, char completionChar, StatisticsUpdate update, @NotNull Editor editor, @NotNull Project project, int caretOffset, OffsetMap offsetMap, List<LookupElement> items, int idEndOffset, int idEndOffsetDelta) { WatchingInsertionContext context; if (editor.getCaretModel().supportsMultipleCarets()) { Ref<WatchingInsertionContext> lastContext = Ref.create(); Editor hostEditor = InjectedLanguageEditorUtil.getTopLevelEditor(editor); boolean wasInjected = hostEditor != editor; PsiDocumentManager.getInstance(project).commitDocument(hostEditor.getDocument()); hostEditor.getCaretModel().runForEachCaret(caret -> { OffsetsInFile targetOffsets; if (!wasInjected) { targetOffsets = topLevelOffsets; } else { targetOffsets = topLevelOffsets.toInjectedIfAny(caret.getOffset()); } doInsertItemForSingleCaret(item, completionChar, update, items, idEndOffsetDelta, lastContext, hostEditor, targetOffsets); }); context = lastContext.get(); } else { PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project); context = insertItem(items, item, completionChar, update, editor, psiFile, caretOffset, idEndOffset, offsetMap); } return context; }