mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user