RUBY-11361: to support correct template creation for templates in files with multiple editors TemplateBuilder.run(Editor, boolean) added, TemplateBuilder.run() deprecated (it doesn't work correctly with such files).

This commit is contained in:
Oleg Sukhodolsky
2012-06-18 19:25:20 +04:00
parent fd5c37eaaa
commit 25d6521956
2 changed files with 18 additions and 1 deletions
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.template;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
@@ -65,6 +66,15 @@ public interface TemplateBuilder {
/**
* Shows the live template and initiates editing process.
* @deprecated doesn't work correctly for files with multiple editors use #run(Editor, boolean) instead
*/
@Deprecated
void run();
/**
* Shows the live template and initiates editing process.
* @param editor editor to use to start editing process.
* @param inline if true then inline template will be created, regular otherwise
*/
void run(@NotNull Editor editor, boolean inline);
}
@@ -268,10 +268,17 @@ public class TemplateBuilderImpl implements TemplateBuilder {
public void run() {
final Project project = myFile.getProject();
VirtualFile file = myFile.getVirtualFile();
assert file != null;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
final Template template = buildTemplate();
assert editor != null : "Editor is null";
run(editor, false);
}
@Override
public void run(@NotNull final Editor editor, final boolean inline) {
final Template template = inline ? buildInlineTemplate() : buildTemplate();
editor.getDocument().replaceString(myContainerElement.getStartOffset(), myContainerElement.getEndOffset(), "");
editor.getCaretModel().moveToOffset(myContainerElement.getStartOffset());