This commit is contained in:
Alexander Zolotov
2014-04-29 14:21:01 +04:00
parent 59454cda37
commit 7a06f6d100
2 changed files with 8 additions and 2 deletions
@@ -27,9 +27,11 @@ import com.intellij.codeInsight.template.CustomLiveTemplate;
import com.intellij.codeInsight.template.CustomLiveTemplateBase;
import com.intellij.codeInsight.template.CustomTemplateCallback;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.diagnostic.AttachmentFactory;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.util.EditorUtil;
@@ -79,6 +81,10 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
public static Map<TemplateImpl, String> filterTemplatesByPrefix(@NotNull Collection<TemplateImpl> templates, @NotNull Editor editor,
int offset, boolean fullMatch, boolean searchInDescription) {
if (offset >= editor.getDocument().getTextLength()) {
Logger.getInstance(ListTemplatesHandler.class).error("Cannot filter templates, index out of bounds. Offset: " + offset,
AttachmentFactory.createAttachment(editor.getDocument()));
}
CharSequence documentText = editor.getDocument().getCharsSequence().subSequence(0, offset);
String prefixWithoutDots = computeDescriptionMatchingPrefix(editor.getDocument(), offset);
@@ -65,9 +65,9 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
return;
}
int offset = parameters.getOffset();
final List<TemplateImpl> availableTemplates = TemplateManagerImpl.listApplicableTemplates(file, offset, false);
Editor editor = parameters.getEditor();
int offset = editor.getCaretModel().getOffset();
final List<TemplateImpl> availableTemplates = TemplateManagerImpl.listApplicableTemplates(file, offset, false);
final Map<TemplateImpl, String> templates = filterTemplatesByPrefix(availableTemplates, editor, offset, false, false);
if (showAllTemplates()) {
final AtomicBoolean templatesShown = new AtomicBoolean(false);