mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
auto-import should be skipped for sync tag editing (WEB-32268)
This commit is contained in:
@@ -6,6 +6,7 @@ import com.intellij.application.options.editor.WebEditorOptions;
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.EmptyExpression;
|
||||
import com.intellij.codeInsight.editorActions.XmlEditUtil;
|
||||
import com.intellij.codeInsight.editorActions.XmlTagNameSynchronizer;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
@@ -24,7 +25,6 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -50,7 +50,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class XmlTagInsertHandler implements InsertHandler<LookupElement> {
|
||||
public static final Key<Boolean> ENFORCING_TAG = Key.create("xml.insert.handler.enforcing.tag");
|
||||
public static final XmlTagInsertHandler INSTANCE = new XmlTagInsertHandler();
|
||||
|
||||
@Override
|
||||
@@ -58,13 +57,13 @@ public class XmlTagInsertHandler implements InsertHandler<LookupElement> {
|
||||
Project project = context.getProject();
|
||||
Editor editor = context.getEditor();
|
||||
// Need to insert " " to prevent creating tags like <tagThis is my text
|
||||
InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(ENFORCING_TAG, Boolean.TRUE);
|
||||
InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(XmlTagNameSynchronizer.SKIP_COMMAND, Boolean.TRUE);
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
editor.getDocument().insertString(offset, " ");
|
||||
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
|
||||
PsiElement current = context.getFile().findElementAt(context.getStartOffset());
|
||||
editor.getDocument().deleteString(offset, offset + 1);
|
||||
InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(ENFORCING_TAG, null);
|
||||
InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(XmlTagNameSynchronizer.SKIP_COMMAND, null);
|
||||
|
||||
final XmlTag tag = PsiTreeUtil.getContextOfType(current, XmlTag.class, true);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.application.options.editor.WebEditorOptions;
|
||||
import com.intellij.codeInsight.completion.XmlTagInsertHandler;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.codeInspection.htmlInspections.RenameTagBeginOrEndIntentionAction;
|
||||
@@ -68,6 +67,7 @@ import java.util.Set;
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public class XmlTagNameSynchronizer implements NamedComponent, CommandListener {
|
||||
public static final Key<Boolean> SKIP_COMMAND = Key.create("tag.name.synchronizer.skip.command");
|
||||
private static final Logger LOG = Logger.getInstance(XmlTagNameSynchronizer.class);
|
||||
private static final Set<Language> SUPPORTED_LANGUAGES = ContainerUtil.set(HTMLLanguage.INSTANCE,
|
||||
XMLLanguage.INSTANCE,
|
||||
@@ -168,8 +168,9 @@ public class XmlTagNameSynchronizer implements NamedComponent, CommandListener {
|
||||
final CharSequence fragment = event.getNewFragment();
|
||||
final int newLength = event.getNewLength();
|
||||
|
||||
if (document.getUserData(XmlTagInsertHandler.ENFORCING_TAG) == Boolean.TRUE) {
|
||||
if (document.getUserData(SKIP_COMMAND) == Boolean.TRUE) {
|
||||
// xml completion inserts extra space after tag name to ensure correct parsing
|
||||
// js auto-import may change beginning of the document when component is imported
|
||||
// we need to ignore it
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user