Editor (final int charTyped, @NotNull Editor editor, @NotNull PsiFile oldFile) { int offset = editor.getCaretModel().getOffset(); // even for uncommitted document try to retrieve injected fragment that has been there recently // we are assuming here that when user is (even furiously) typing, injected language would not change // and thus we can use its lexer to insert closing braces etc List<DocumentWindow> injected = InjectedLanguageManager.getInstance(oldFile.getProject()).getCachedInjectedDocumentsInRange(oldFile, ProperTextRange.create(offset, offset)); for (DocumentWindow documentWindow : injected) { if (documentWindow.isValid() && documentWindow.containsRange(offset, offset)) { PsiFile injectedFile = PsiDocumentManager.getInstance(oldFile.getProject()).getPsiFile(documentWindow); if (injectedFile != null) { Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile); // IDEA-52375/WEB-9105 fix: last quote in editable fragment should be handled by outer language quote handler TextRange hostRange = documentWindow.getHostRange(offset); CharSequence sequence = editor.getDocument().getCharsSequence(); if (sequence.length() > offset && charTyped != Character.codePointAt(sequence, offset) || hostRange != null && hostRange.contains(offset)) { return injectedEditor; } } } } return editor; }