void (final @NotNull InsertionContext context, final @NotNull LookupElement item) { final Editor editor = context.getEditor(); final Document document = editor.getDocument(); final int caretOffset = editor.getCaretModel().getOffset(); final PsiFile file = context.getFile(); final CharSequence chars = document.getCharsSequence(); final String quote = XmlEditUtil.getAttributeQuote(file); final boolean insertQuotes = WebEditorOptions.getInstance().isInsertQuotesForAttributeValue() && StringUtil.isNotEmpty(quote); final boolean hasQuotes = CharArrayUtil.regionMatches(chars, caretOffset, "=\"") || CharArrayUtil.regionMatches(chars, caretOffset, "='"); if (!hasQuotes) { if (CharArrayUtil.regionMatches(chars, caretOffset, "=")) { document.deleteString(caretOffset, caretOffset + 1); } PsiElement fileContext = file.getContext(); String toInsert = null; if(fileContext != null) { if (fileContext.getText().startsWith("\"")) toInsert = "=''"; if (fileContext.getText().startsWith("'")) toInsert = "=\"\""; } if (toInsert == null) { toInsert = "=" + quote + quote; } if (!insertQuotes) toInsert = "="; if (caretOffset < document.getTextLength() && "/> \n\t\r".indexOf(document.getCharsSequence().charAt(caretOffset)) < 0) { document.insertString(caretOffset, toInsert + " "); } else { document.insertString(caretOffset, toInsert); } if ('=' == context.getCompletionChar()) { context.setAddCompletionChar(false); // IDEA-19449 } } editor.getCaretModel().moveToOffset(caretOffset + (insertQuotes || hasQuotes ? 2 : 1)); TabOutScopesTracker.getInstance().registerEmptyScopeAtCaret(context.getEditor()); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); AutoPopupController.getInstance(editor.getProject()).scheduleAutoPopup(editor); if (myNamespaceToInsert != null && file instanceof XmlFile) { final PsiElement element = file.findElementAt(context.getStartOffset()); final XmlTag tag = element != null ? PsiTreeUtil.getParentOfType(element, XmlTag.class) : null; if (tag != null) { String prefix = ExtendedTagInsertHandler.suggestPrefix((XmlFile)file, myNamespaceToInsert); if (prefix != null) { prefix = makePrefixUnique(prefix, tag); final XmlNamespaceHelper helper = XmlNamespaceHelper.getHelper(context.getFile()); if (helper != null) { final Project project = context.getProject(); PsiDocumentManager.getInstance(project).commitDocument(document); qualifyWithPrefix(prefix, element); helper.insertNamespaceDeclaration((XmlFile)file, editor, Collections.singleton( myNamespaceToInsert), prefix, null); } } } } }