Merge remote-tracking branch 'origin/master'
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Fri, 30 Jan 2015 11:40:50 +0000 (14:40 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Fri, 30 Jan 2015 11:40:50 +0000 (14:40 +0300)
1  2 
platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java

index 2c230e536f7c556fcdcdb210bd4ea351dc247416,ff8e7e59ce80e9add785c9d4c057c47064d5e46d..423b95dffc7fcf1a651e8312c8b51294a03cabf2
@@@ -25,10 -25,7 +25,7 @@@ import com.intellij.codeInsight.highlig
  import com.intellij.codeInsight.highlighting.NontrivialBraceMatcher;
  import com.intellij.codeInsight.template.impl.editorActions.TypedActionHandlerBase;
  import com.intellij.injected.editor.DocumentWindow;
- import com.intellij.lang.ASTNode;
- import com.intellij.lang.Language;
- import com.intellij.lang.LanguageParserDefinitions;
- import com.intellij.lang.ParserDefinition;
+ import com.intellij.lang.*;
  import com.intellij.openapi.actionSystem.CommonDataKeys;
  import com.intellij.openapi.actionSystem.DataContext;
  import com.intellij.openapi.application.ApplicationManager;
@@@ -40,7 -37,6 +37,7 @@@ import com.intellij.openapi.editor.ex.E
  import com.intellij.openapi.editor.highlighter.EditorHighlighter;
  import com.intellij.openapi.editor.highlighter.HighlighterIterator;
  import com.intellij.openapi.extensions.Extensions;
 +import com.intellij.openapi.fileEditor.FileDocumentManager;
  import com.intellij.openapi.fileTypes.FileType;
  import com.intellij.openapi.fileTypes.FileTypes;
  import com.intellij.openapi.fileTypes.LanguageFileType;
@@@ -55,6 -51,7 +52,7 @@@ import com.intellij.psi.tree.IElementTy
  import com.intellij.psi.tree.TokenSet;
  import com.intellij.psi.util.PsiUtilBase;
  import com.intellij.util.IncorrectOperationException;
+ import com.intellij.util.containers.ContainerUtil;
  import com.intellij.util.text.CharArrayUtil;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
@@@ -92,6 -89,7 +90,7 @@@ public class TypedHandler extends Typed
            return entry.getValue();
          }
        }
+       return LanguageQuoteHandling.INSTANCE.forLanguage(baseLanguage);
      }
      return quoteHandler;
    }
      }
  
      if (!CodeInsightUtilBase.prepareEditorForWrite(originalEditor)) return;
 +    if (!FileDocumentManager.getInstance().requestWriting(originalEditor.getDocument(), project)) {
 +       return;
 +    }
  
      final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
      final Document originalDocument = originalEditor.getDocument();
            }
          }
          else if ('"' == charTyped || '\'' == charTyped || '`' == charTyped/* || '/' == charTyped*/) {
-           if (handleQuote(editor, charTyped, dataContext, file)) return;
+           if (handleQuote(editor, charTyped, file)) return;
          }
  
          long modificationStampBeforeTyping = editor.getDocument().getModificationStamp();
            indentOpenedParenth(project, editor);
          }
        }
-     }, true);
+     });
    }
  
    private static void type(Editor editor, char charTyped) {
        AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
      }
    }
+   
+   public static void commitDocumentIfCurrentCaretIsNotTheFirstOne(@NotNull Editor editor, @NotNull Project project) {
+     if (ContainerUtil.getFirstItem(editor.getCaretModel().getAllCarets()) != editor.getCaretModel().getCurrentCaret()) {
+       PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
+     }
+   }
  
    private static boolean isAutoPopup(@NotNull Editor editor, @NotNull PsiFile file, char charTyped) {
      final int offset = editor.getCaretModel().getOffset() - 1;
      return true;
    }
  
-   private boolean handleQuote(@NotNull Editor editor, char quote, @NotNull DataContext dataContext, @NotNull PsiFile file) {
+   private static boolean handleQuote(@NotNull Editor editor, char quote, @NotNull PsiFile file) {
      if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE) return false;
      final QuoteHandler quoteHandler = getQuoteHandler(file, editor);
      if (quoteHandler == null) return false;