do not activate only live template because it may be ambiguous
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Mon, 1 Mar 2010 13:44:09 +0000 (16:44 +0300)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Mon, 1 Mar 2010 13:44:09 +0000 (16:44 +0300)
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java
xml/impl/src/com/intellij/codeInsight/template/XmlZenCodingTemplate.java

index aff173c2b22433993241e2aab51a0eead452878b..b8b4a5bf8f24aae46237c2536cf19384cf343064 100644 (file)
@@ -227,11 +227,11 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo
     if (shortcutChar == templateSettings.getDefaultShortcutChar()) {
       for (final CustomLiveTemplate customLiveTemplate : CustomLiveTemplate.EP_NAME.getExtensions()) {
         final CustomTemplateCallback callback = new CustomTemplateCallback(editor, file);
+        callback.fixInitialEditorState();
         String key = customLiveTemplate.computeTemplateKey(callback);
         if (key != null) {
           int offset = callback.getEditor().getCaretModel().getOffset();
           callback.getEditor().getDocument().deleteString(offset - key.length(), offset);
-          callback.fixInitialEditorState();
           customLiveTemplate.execute(key, callback, new TemplateInvokationListener() {
             public void finished(boolean inSeparateEvent) {
               callback.finish();
index ea7f8595e570f9eb7551b397e98272f56944f461..129ae8838e58da15bccc761c976e1a9791254934 100644 (file)
@@ -310,10 +310,17 @@ public class XmlZenCodingTemplate implements CustomLiveTemplate {
         int startOffset = parentStart > lineStart ? parentStart : lineStart;
         String key = computeKey(editor, startOffset);
         List<MyToken> tokens = parse(key, callback);
-        if (tokens != null) {
-          if (check(tokens)) {
-            return key;
+        if (tokens != null && check(tokens)) {
+          if (tokens.size() == 2) {
+            MyToken token = tokens.get(0);
+            if (token instanceof MyTemplateToken) {
+              if (key.equals(((MyTemplateToken)token).myKey) && callback.isLiveTemplateApplicable(key)) {
+                // do not activate only live template
+                return null;
+              }
+            }
           }
+          return key;
         }
         if (element != null) {
           element = element.getParent();