当前位置: 首页>>代码示例>>Java>>正文


Java EditorModificationUtil.insertStringAtCaret方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.EditorModificationUtil.insertStringAtCaret方法的典型用法代码示例。如果您正苦于以下问题:Java EditorModificationUtil.insertStringAtCaret方法的具体用法?Java EditorModificationUtil.insertStringAtCaret怎么用?Java EditorModificationUtil.insertStringAtCaret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.EditorModificationUtil的用法示例。


在下文中一共展示了EditorModificationUtil.insertStringAtCaret方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUpdateAfterInsertingIdenticalText

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public void testUpdateAfterInsertingIdenticalText() {
  PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, "class Foo {\n" +
                                                                     "    void m() {\n" +
                                                                     "    }\n" +
                                                                     "<caret>}\n");
  PsiMethod method = file.getClasses()[0].getMethods()[0];
  TextRange originalRange = method.getTextRange();
  SmartPsiElementPointer pointer = createPointer(method);

  EditorModificationUtil.insertStringAtCaret(myEditor, "    void m() {\n" +
                                                       "    }\n");
  PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
  PsiElement element = pointer.getElement();
  assertNotNull(element);
  TextRange newRange = element.getTextRange();
  assertEquals(originalRange, newRange);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SmartPsiElementPointersTest.java

示例2: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  Editor editor = context.getEditor();
  if (context.getCompletionChar() == ' ') return;
  Project project = editor.getProject();
  if (project != null) {
    if (!isCharAtSpace(editor)) {
      EditorModificationUtil.insertStringAtCaret(editor, " ");
      PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    }
    else {
      editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 1);
    }
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AddSpaceInsertHandler.java

示例3: deleteToTargetPosition

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public static void deleteToTargetPosition(@NotNull Editor editor, @NotNull LogicalPosition pos) {
  LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition();
  if (logicalPosition.line != pos.line) {
    LOGGER.error("Unexpected caret position: " + logicalPosition + ", target indent position: " + pos);
    return;
  }
  if (pos.column < logicalPosition.column) {
    int targetOffset = editor.logicalPositionToOffset(pos);
    int offset = editor.getCaretModel().getOffset();
    editor.getSelectionModel().setSelection(targetOffset, offset);
    EditorModificationUtil.deleteSelectedText(editor);
  }
  else if (pos.column > logicalPosition.column) {
    EditorModificationUtil.insertStringAtCaret(editor, StringUtil.repeatSymbol(' ', pos.column - logicalPosition.column));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:BackspaceHandler.java

示例4: invoke

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
  if (element.getNode().getElementType() == TokenType.WHITE_SPACE) element = PsiTreeUtil.prevVisibleLeaf(element);

  SchemaValueTypeRef valueTypeRef = PsiTreeUtil.getParentOfType(element, SchemaValueTypeRef.class);
  if (valueTypeRef != null) {
    int endOffset = valueTypeRef.getNode().getTextRange().getEndOffset();
    editor.getCaretModel().moveToOffset(endOffset);
    EditorModificationUtil.insertStringAtCaret(editor, " default ");

    ApplicationManager.getApplication().invokeLater(() -> {
      AnActionEvent event = AnActionEvent.createFromDataContext("AddDefaultAction",
          new Presentation(), ((EditorEx) editor).getDataContext());

      new CodeCompletionAction().actionPerformed(event);
    });
  }
}
 
开发者ID:SumoLogic,项目名称:epigraph,代码行数:19,代码来源:AddRetroAction.java

示例5: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  Editor editor = context.getEditor();
  char completionChar = context.getCompletionChar();
  if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) return;
  Project project = editor.getProject();
  if (project != null) {
    if (!isCharAtSpace(editor)) {
      EditorModificationUtil.insertStringAtCaret(editor, " ");
      PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    }
    else if (shouldOverwriteExistingSpace(editor)) {
      editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 1);
    }
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:AddSpaceInsertHandler.java

示例6: doEnter

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified)
{
	if(isModified)
	{
		return false;
	}
	final PsiElement atCaret = psiElement.getContainingFile().findElementAt(editor.getCaretModel().getOffset());
	final PsiComment comment = PsiTreeUtil.getParentOfType(atCaret, PsiComment.class, false);
	if(comment != null)
	{
		plainEnter(editor);
		if(comment.getTokenType() == JavaTokenType.END_OF_LINE_COMMENT)
		{
			EditorModificationUtil.insertStringAtCaret(editor, "// ");
		}
		return true;
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:CommentBreakerEnterProcessor.java

示例7: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context1, LookupElement item) {
    Editor editor = context1.getEditor();

    //If they typed the element we should replace the thing they're typing with the correct case
    // Even though Torque is case-insensitive it looks bad if we don't
    PsiElement editing = context1.getFile().findElementAt(context1.getStartOffset());
    if (editing != null) {
        //Delete the element they were typing (note to only go to their carat position)
        editor.getDocument().deleteString(editing.getTextOffset(), editor.getCaretModel().getCurrentCaret().getOffset());
        //And insert the correctly cased version
        EditorModificationUtil.insertStringAtCaret(editor, item.getLookupString(), true);
    }
}
 
开发者ID:CouleeApps,项目名称:TS-IJ,代码行数:15,代码来源:TSCaseCorrectingInsertHandler.java

示例8: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  Editor editor = context.getEditor();
  Project project = editor.getProject();

  if (project != null) {
    EditorModificationUtil.insertStringAtCaret(
        editor, closingTagBeforeCaret + closingTagAfterCaret);
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    EditorModificationUtil.moveCaretRelatively(editor, -closingTagAfterCaret.length());
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:12,代码来源:PostfixInsertHandler.java

示例9: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext insertionContext, final LookupElement lookupElement) {
    handleStartingQuote(insertionContext, lookupElement);
    handleEndingQuote(insertionContext);

    if (!StringUtils.nextCharAfterSpacesAndQuotesIsColon(getStringAfterAutoCompletedValue(insertionContext))) {
        final String suffixWithCaret = field.getJsonPlaceholderSuffix(getIndentation(insertionContext, lookupElement));
        final String suffixWithoutCaret = suffixWithCaret.replace(CARET, "");
        EditorModificationUtil.insertStringAtCaret(
                insertionContext.getEditor(),
                withOptionalComma(suffixWithoutCaret, insertionContext), false, true,
                getCaretIndex(suffixWithCaret));
    }
}
 
开发者ID:zalando,项目名称:intellij-swagger,代码行数:15,代码来源:JsonInsertFieldHandler.java

示例10: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, final LookupElement item) {
    if (!StringUtils.nextCharAfterSpacesAndQuotesIsColon(getStringAfterAutoCompletedValue(context))) {
        final String suffixWithCaret = field.getYamlPlaceholderSuffix(getIndentation(context, item));
        final String suffixWithoutCaret = suffixWithCaret.replace(CARET, "");
        EditorModificationUtil.insertStringAtCaret(context.getEditor(), suffixWithoutCaret, false, true, getCaretIndex(suffixWithCaret));
    }
}
 
开发者ID:zalando,项目名称:intellij-swagger,代码行数:9,代码来源:YamlInsertFieldHandler.java

示例11: setupEditor

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public static void setupEditor(PsiMethod method, final Editor newEditor) {
  PsiCodeBlock body = method.getBody();
  if (body != null) {
    PsiElement l = PsiTreeUtil.skipSiblingsForward(body.getLBrace(), PsiWhiteSpace.class);
    PsiElement r = PsiTreeUtil.skipSiblingsBackward(body.getRBrace(), PsiWhiteSpace.class);
    if (l != null && r != null) {
      int start = l.getTextRange().getStartOffset();
      int end = r.getTextRange().getEndOffset();
      newEditor.getCaretModel().moveToOffset(Math.max(start, end));
      if (end < start) {
        newEditor.getCaretModel().moveToOffset(end + 1);
        CodeStyleManager styleManager = CodeStyleManager.getInstance(method.getProject());
        PsiFile containingFile = method.getContainingFile();
        final String lineIndent = styleManager.getLineIndent(containingFile, Math.min(start, end));
        PsiDocumentManager manager = PsiDocumentManager.getInstance(method.getProject());
        manager.doPostponedOperationsAndUnblockDocument(manager.getDocument(containingFile));
        EditorModificationUtil.insertStringAtCaret(newEditor, lineIndent);
        EditorModificationUtil.insertStringAtCaret(newEditor, "\n", false, false);
      }
      else {
        //correct position caret for groovy and java methods
        final PsiGenerationInfo<PsiMethod> info = OverrideImplementUtil.createGenerationInfo(method);
        info.positionCaret(newEditor, true);
      }
      newEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:CreateFromUsageUtils.java

示例12: doEnter

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
  if (isModified) return false;
  final PsiElement atCaret = psiElement.getContainingFile().findElementAt(editor.getCaretModel().getOffset());
  final PsiComment comment = PsiTreeUtil.getParentOfType(atCaret, PsiComment.class, false);
  if (comment != null) {
    plainEnter(editor);
    if (comment.getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
      EditorModificationUtil.insertStringAtCaret(editor, "// ");
    }
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:CommentBreakerEnterProcessor.java

示例13: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
  LookupElement item = getDelegate();
  Project project = context.getProject();
  Editor editor = context.getEditor();

  PsiDocumentManager.getInstance(project).commitAllDocuments();

  TextRange range = myState.getCurrentVariableRange();
  final TemplateLookupSelectionHandler handler = item.getUserData(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM);
  if (handler != null && range != null) {
    handler.itemSelected(item, context.getFile(), context.getDocument(), range.getStartOffset(), range.getEndOffset());
  }
  else {
    super.handleInsert(context);
  }

  if (context.getCompletionChar() == '.') {
    EditorModificationUtil.insertStringAtCaret(editor, ".");
    AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    return;
  }

  if (!myState.isFinished()) {
    myState.calcResults(true);
  }

  myState.nextTab();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:TemplateExpressionLookupElement.java

示例14: insertLineFeedInString

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
private static void insertLineFeedInString(Editor editor,
                                           DataContext dataContext,
                                           EditorActionHandler originalHandler,
                                           boolean isInsertIndent) {
  if (isInsertIndent) {
    originalHandler.execute(editor, dataContext);
  }
  else {
    EditorModificationUtil.insertStringAtCaret(editor, "\n");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:GroovyEnterHandler.java

示例15: handleInsert

import com.intellij.openapi.editor.EditorModificationUtil; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Project project = editor.getProject();
  if (project != null) {
    EditorModificationUtil.insertStringAtCaret(editor, " \"\"");
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 1);
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:13,代码来源:JSGraphQLEndpointImportInsertHandler.java


注:本文中的com.intellij.openapi.editor.EditorModificationUtil.insertStringAtCaret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。