fix sync after completion in injection

#WEB-17822 fixed
This commit is contained in:
Dennis Ushakov
2015-08-20 14:49:44 +03:00
parent 6ab6297a93
commit 769ae29a70
2 changed files with 11 additions and 3 deletions
@@ -42,6 +42,7 @@ import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlTokenType;
@@ -63,13 +64,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
editor.getDocument().putUserData(ENFORCING_TAG, Boolean.TRUE);
InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(ENFORCING_TAG, 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);
editor.getDocument().putUserData(ENFORCING_TAG, null);
InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(ENFORCING_TAG, null);
final XmlTag tag = PsiTreeUtil.getContextOfType(current, XmlTag.class, true);
@@ -65,7 +65,14 @@ public abstract class XmlSyncTagTest extends LightPlatformCodeInsightFixtureTest
}
protected void doTestCompletion(final String text, final String toType, final String result) {
myFixture.configureByText(XmlFileType.INSTANCE, text);
doTestCompletion(XmlFileType.INSTANCE, text, toType, result);
}
protected void doTestCompletion(final FileType fileType,
final String text,
final String toType,
final String result) {
myFixture.configureByText(fileType, text);
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {