Search in sources :

Example 1 with ExpandLiveTemplateByTabAction

use of com.intellij.codeInsight.template.impl.editorActions.ExpandLiveTemplateByTabAction in project Perl5-IDEA by Camelcade.

the class PerlLightTestCase method doLiveTemplateTest.

protected void doLiveTemplateTest(@NotNull String fileName, @NotNull String textToType) {
    initWithFileSmart(fileName);
    Editor editor = getEditor();
    Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    List<Integer> caretsOffsets = getAndRemoveCarets();
    String originalText = document.getText();
    StringBuilder sb = new StringBuilder();
    for (Integer offset : caretsOffsets) {
        WriteCommandAction.runWriteCommandAction(getProject(), () -> {
            caretModel.moveToOffset(offset);
            EditorModificationUtil.insertStringAtCaret(editor, textToType);
            String textBeforeAction = document.getText();
            myFixture.testAction(new ExpandLiveTemplateByTabAction());
            if (!StringUtil.equals(document.getText(), textBeforeAction)) {
                sb.append(StringUtil.repeat("-", 80)).append("\n").append("Caret offset: ").append(offset).append("\n").append(StringUtil.repeat("-", 80)).append("\n").append(getEditorTextWithCaretsAndSelections());
            }
            TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
            if (templateState != null) {
                templateState.gotoEnd(true);
            }
            document.setText(originalText);
        });
    }
    UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString());
}
Also used : ExpandLiveTemplateByTabAction(com.intellij.codeInsight.template.impl.editorActions.ExpandLiveTemplateByTabAction) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TemplateState(com.intellij.codeInsight.template.impl.TemplateState)

Aggregations

TemplateState (com.intellij.codeInsight.template.impl.TemplateState)1 ExpandLiveTemplateByTabAction (com.intellij.codeInsight.template.impl.editorActions.ExpandLiveTemplateByTabAction)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1