• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EditorModificationUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



EditorModificationUtil类属于com.intellij.openapi.editor包,在下文中一共展示了EditorModificationUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


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


示例17: handleSemicolon

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
private static boolean handleSemicolon(Editor editor, FileType fileType)
{
	if(fileType != JavaFileType.INSTANCE)
	{
		return false;
	}
	int offset = editor.getCaretModel().getOffset();
	if(offset == editor.getDocument().getTextLength())
	{
		return false;
	}

	char charAt = editor.getDocument().getCharsSequence().charAt(offset);
	if(charAt != ';')
	{
		return false;
	}

	EditorModificationUtil.moveCaretRelatively(editor, 1);
	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:JavaTypedHandler.java


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


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


示例20: preExpand

import com.intellij.openapi.editor.EditorModificationUtil; //导入依赖的package包/类
@Override
public void preExpand(@NotNull final PsiFile file, @NotNull final Editor editor) {
	ApplicationManager.getApplication().assertIsDispatchThread();

	if (isSemicolonNeeded(file, editor)) {
		ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().runUndoTransparentAction(
			() -> {
				EditorModificationUtil.insertStringAtCaret(editor, ";", false, false);
				PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
			}));
	}
}
 
开发者ID:xylo,项目名称:intellij-postfix-templates,代码行数:13,代码来源:CustomPostfixTemplateProvider.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PrimitiveTypeTree类代码示例发布时间:2022-05-21
下一篇:
Java ServiceDialog类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap