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


Java EditorModificationUtil类代码示例

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


EditorModificationUtil类属于com.intellij.openapi.editor包,在下文中一共展示了EditorModificationUtil类的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: executeWriteAction

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public void executeWriteAction(final Editor editor, DataContext dataContext) {
  if(!editor.getSelectionModel().hasSelection(true)) {
    if (Registry.is(CopyAction.SKIP_COPY_AND_CUT_FOR_EMPTY_SELECTION_KEY)) {
      return;
    }
    editor.getCaretModel().runForEachCaret(new CaretAction() {
      @Override
      public void perform(Caret caret) {
        editor.getSelectionModel().selectLineAtCaret();
      }
    });
  }
  editor.getSelectionModel().copySelectionToClipboard();
  EditorModificationUtil.deleteSelectedTextForAllCarets(editor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CutAction.java

示例3: executeWriteAction

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
  CopyPasteManager.getInstance().stopKillRings();

  boolean camelMode = editor.getSettings().isCamelWords();
  if (myNegateCamelMode) {
    camelMode = !camelMode;
  }

  if (editor.getSelectionModel().hasSelection()) {
    EditorModificationUtil.deleteSelectedText(editor);
    return;
  }

  deleteToWordEnd(editor, camelMode);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:DeleteToWordEndAction.java

示例4: 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

示例5: 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

示例6: insert

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
private static void insert(final String fqn, final PsiElement element, final Editor editor, final QualifiedNameProvider provider) {
  final Project project = editor.getProject();
  if (project == null) return;

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  documentManager.commitDocument(editor.getDocument());

  final PsiFile file = documentManager.getPsiFile(editor.getDocument());
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          Document document = editor.getDocument();
          documentManager.doPostponedOperationsAndUnblockDocument(document);
          documentManager.commitDocument(document);
          EditorModificationUtil.deleteSelectedText(editor);
          provider.insertQualifiedName(fqn, element, editor, project);
        }
      });
    }
  }, IdeBundle.message("command.pasting.reference"), null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:PasteReferenceProvider.java

示例7: 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

示例8: executeWriteAction

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  final Clipboard clip = editor.getComponent().getToolkit().getSystemSelection();
  if (clip != null) {
    Transferable res = null;
    try {
      res = clip.getContents(null);
    }
    catch (Exception e) {
      if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
        LOG.info(e);
        Messages.showErrorDialog(editor.getProject(), "Cannot paste from X11 clipboard: " + e.getLocalizedMessage(), "Cannot Paste");
        return;
      }
    }
    editor.putUserData(EditorEx.LAST_PASTED_REGION, EditorModificationUtil.pasteFromTransferrable(res, editor));
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:PasteFromX11Action.java

示例9: beforeCharTyped

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile editedFile, final FileType fileType) {
    if ((editedFile.getLanguage() instanceof XQueryLanguage) && c == '>') {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (file == null) return Result.CONTINUE;
        final int offset = editor.getCaretModel().getOffset();
        FileViewProvider provider = file.getViewProvider();
        PsiElement element = provider.findElementAt(offset, XQueryLanguage.class);

        if (element != null && element.getNode() != null && (
                element.getNode().getElementType() == XQueryTypes.XMLTAGEND ||
                        element.getNode().getElementType() == XQueryTypes.XMLEMPTYELEMENTEND)) {
            EditorModificationUtil.moveCaretRelatively(editor, 1);
            editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
            return Result.STOP;
        }
    }
    return Result.CONTINUE;
}
 
开发者ID:ligasgr,项目名称:intellij-xquery,代码行数:21,代码来源:XQueryXmlGtTypedHandler.java

示例10: afterJump

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public void afterJump() {
    final Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (inSameEditor()) {
                selectJumpArea();

                _se.getSelectionModel().copySelectionToClipboard();
                EditorModificationUtil.deleteSelectedText(_se);
                _se.getSelectionModel().removeSelection();
            }
        }
    };

    AppUtil.runWriteAction(runnable, _se);
}
 
开发者ID:whunmr,项目名称:emacsIDEAs,代码行数:18,代码来源:CutAfterJumpCommand.java

示例11: executeWriteAction

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@RequiredWriteAction
@Override
public void executeWriteAction(final Editor editor, DataContext dataContext) {
  if(!editor.getSelectionModel().hasSelection(true)) {
    if (Registry.is(CopyAction.SKIP_COPY_AND_CUT_FOR_EMPTY_SELECTION_KEY)) {
      return;
    }
    editor.getCaretModel().runForEachCaret(new CaretAction() {
      @Override
      public void perform(Caret caret) {
        editor.getSelectionModel().selectLineAtCaret();
      }
    });
  }
  editor.getSelectionModel().copySelectionToClipboard();
  EditorModificationUtil.deleteSelectedTextForAllCarets(editor);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:CutAction.java

示例12: 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

示例13: checkAutoPopup

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public Result checkAutoPopup(char charTyped, final Project project, final Editor editor, final PsiFile file) {
  LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);

  if (LOG.isDebugEnabled()) {
    LOG.debug("checkAutoPopup: character=" + charTyped + ";");
    LOG.debug("phase=" + CompletionServiceImpl.getCompletionPhase());
    LOG.debug("lookup=" + lookup);
    LOG.debug("currentCompletion=" + CompletionServiceImpl.getCompletionService().getCurrentCompletion());
  }

  if (lookup != null) {
    if (editor.getSelectionModel().hasSelection()) {
      lookup.performGuardedChange(() -> EditorModificationUtil.deleteSelectedText(editor));
    }
    return Result.STOP;
  }

  if (Character.isLetter(charTyped) || charTyped == '_') {
    AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
    return Result.STOP;
  }

  return Result.CONTINUE;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:26,代码来源:CompletionAutoPopupHandler.java

示例14: doExecute

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
  final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
  if (templateState != null && !templateState.isFinished()) {
    final TextRange range = templateState.getCurrentVariableRange();
    final int caretOffset = editor.getCaretModel().getOffset();
    if (range != null && shouldStayInsideVariable(range, caretOffset)) {
      int selectionOffset = editor.getSelectionModel().getLeadSelectionOffset();
      int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset();
      LogicalPosition logicalPosition = editor.offsetToLogicalPosition(offsetToMove).leanForward(myIsHomeHandler);
      editor.getCaretModel().moveToLogicalPosition(logicalPosition);
      EditorModificationUtil.scrollToCaret(editor);
      if (myWithSelection) {
        editor.getSelectionModel().setSelection(selectionOffset, offsetToMove);
      }
      else {
        editor.getSelectionModel().removeSelection();
      }
      return;
    }
  }
  myOriginalHandler.execute(editor, caret, dataContext);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:TemplateLineStartEndHandler.java

示例15: insert

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
private static void insert(final String fqn, final PsiElement element, final Editor editor, final QualifiedNameProvider provider) {
  final Project project = editor.getProject();
  if (project == null) return;

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  documentManager.commitDocument(editor.getDocument());

  final PsiFile file = documentManager.getPsiFile(editor.getDocument());
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> {
    Document document = editor.getDocument();
    documentManager.doPostponedOperationsAndUnblockDocument(document);
    documentManager.commitDocument(document);
    EditorModificationUtil.deleteSelectedText(editor);
    provider.insertQualifiedName(fqn, element, editor, project);
  }), IdeBundle.message("command.pasting.reference"), null);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:PasteReferenceProvider.java


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