Java 类com.intellij.openapi.editor.actionSystem.EditorActionManager 实例源码

项目:educational-plugin    文件:StudyUtils.java   
public static void drawAllAnswerPlaceholders(Editor editor, TaskFile taskFile) {
  editor.getMarkupModel().removeAllHighlighters();
  final Project project = editor.getProject();
  if (project == null) return;
  final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
  for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
    final JBColor color = taskManager.getColor(answerPlaceholder);
    EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, color);
  }

  final Document document = editor.getDocument();
  EditorActionManager.getInstance()
    .setReadonlyFragmentModificationHandler(document, new EduAnswerPlaceholderDeleteHandler(editor));
  EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
  editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
}
项目:intellij-ce-playground    文件:BracesTailType.java   
@Override
public int processTail(final Editor editor, int tailOffset) {
  int startOffset = tailOffset;

  CharSequence seq = editor.getDocument().getCharsSequence();
  int nextNonWs = CharArrayUtil.shiftForward(seq, tailOffset, " \t");
  if (nextNonWs < seq.length() && seq.charAt(nextNonWs) == '{') {
    tailOffset = nextNonWs + 1;
  } else {
    tailOffset = insertChar(editor, startOffset, '{');
  }

  tailOffset = reformatBrace(editor, tailOffset, startOffset);

  if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, tailOffset, getFileType(editor))) {
    new EnterHandler(EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER))
      .executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
    return editor.getCaretModel().getOffset();
  }
  return tailOffset;
}
项目:intellij-ce-playground    文件:EditorTestUtil.java   
public static void performTypingAction(Editor editor, char c) {
  EditorActionManager actionManager = EditorActionManager.getInstance();
  if (c == BACKSPACE_FAKE_CHAR) {
    executeAction(editor, IdeActions.ACTION_EDITOR_BACKSPACE);
  } else if (c == SMART_ENTER_FAKE_CHAR) {
    executeAction(editor, IdeActions.ACTION_EDITOR_COMPLETE_STATEMENT);
  } else if (c == SMART_LINE_SPLIT_CHAR) {
    executeAction(editor, IdeActions.ACTION_EDITOR_SPLIT);
  }
  else if (c == '\n') {
    executeAction(editor, IdeActions.ACTION_EDITOR_ENTER);
  }
  else {
    TypedAction action = actionManager.getTypedAction();
    action.actionPerformed(editor, c, DataManager.getInstance().getDataContext(editor.getContentComponent()));
  }
}
项目:intellij-ce-playground    文件:HungryBackspaceAction.java   
@Override
public void executeWriteAction(@NotNull Editor editor, Caret caret, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int caretOffset = editor.getCaretModel().getOffset();
  if (caretOffset < 1) {
    return;
  }

  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(caretOffset - 1);
  if (!selectionModel.hasSelection() && StringUtil.isWhiteSpace(c)) {
    int startOffset = CharArrayUtil.shiftBackward(text, caretOffset - 2, "\t \n") + 1;
    document.deleteString(startOffset, caretOffset);
  }
  else {
    final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
    handler.execute(editor, caret, dataContext);
  }
}
项目:intellij-ce-playground    文件:SelectionQuotingTypedHandlerTest.java   
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(FileTypes.PLAIN_TEXT, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
项目:intellij-ce-playground    文件:ConsoleViewImplTest.java   
public void testTypeInEmptyConsole() throws Exception {
  final ConsoleViewImpl console = createConsole();
  try {
    console.clear();
    EditorActionManager actionManager = EditorActionManager.getInstance();
    final DataContext dataContext = DataManager.getInstance().getDataContext();
    TypedAction action = actionManager.getTypedAction();
    action.actionPerformed(console.getEditor(), 'h', dataContext);
    assertEquals(1, console.getContentSize());
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  finally {
    Disposer.dispose(console);
  }
}
项目:intellij-ce-playground    文件:ConsoleViewImplTest.java   
public void testTypingAfterMultipleCR() throws Exception {
  final EditorActionManager actionManager = EditorActionManager.getInstance();
  final TypedAction typedAction = actionManager.getTypedAction();
  final TestDataProvider dataContext = new TestDataProvider(getProject());

  final ConsoleViewImpl console = createConsole();
  final Editor editor = console.getEditor();
  try {
    console.print("System output\n", ConsoleViewContentType.SYSTEM_OUTPUT);
    console.print("\r\r\r\r\r\r\r", ConsoleViewContentType.NORMAL_OUTPUT);
    console.flushDeferredText();

    typedAction.actionPerformed(editor, '1', dataContext);
    typedAction.actionPerformed(editor, '2', dataContext);

    assertEquals("System output\n12", editor.getDocument().getText());
  }
  finally {
    Disposer.dispose(console);
  }
}
项目:intellij-ce-playground    文件:CodeCompletionHandlerBase.java   
private static void addCompletionChar(Project project,
                                      CompletionAssertions.WatchingInsertionContext context,
                                      LookupElement item,
                                      Editor editor, CompletionProgressIndicator indicator, char completionChar) {
  int tailOffset = context.getTailOffset();
  if (tailOffset < 0) {
    LOG.info("tailOffset<0 after inserting " + item + " of " + item.getClass() + "; invalidated at: " + context.invalidateTrace + "\n--------");
  }
  else {
    editor.getCaretModel().moveToOffset(tailOffset);
  }
  if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
    final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language != null) {
      for (SmartEnterProcessor processor : SmartEnterProcessors.INSTANCE.forKey(language)) {
        if (processor.processAfterCompletion(editor, indicator.getParameters().getOriginalFile())) break;
      }
    }
  }
  else if (!editor.getCaretModel().supportsMultipleCarets()) { // this will be done outside of runForEach caret context
    DataContext dataContext = DataManager.getInstance().getDataContext(editor.getContentComponent());
    EditorActionManager.getInstance().getTypedAction().getHandler().execute(editor, completionChar, dataContext);
  }
}
项目:intellij-ce-playground    文件:FindUtil.java   
public static boolean replace(Project project, Editor editor, int offset, FindModel model, ReplaceDelegate delegate) {
  Document document = editor.getDocument();

  if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
    return false;
  }

  document.startGuardedBlockChecking();
  boolean toPrompt = model.isPromptOnReplace();

  try {
    doReplace(project, editor, model, document, offset, toPrompt, delegate);
  }
  catch (ReadOnlyFragmentModificationException e) {
    EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
  }
  finally {
    document.stopGuardedBlockChecking();
  }

  return true;
}
项目:intellij-ce-playground    文件:XmlPerformanceTest.java   
private void doIndentTest(int time) {
  configureByFile(getBasePath() + getTestName(false)+".xml");
  doHighlighting();
  myEditor.getSelectionModel().setSelection(0,myEditor.getDocument().getTextLength());

  PlatformTestUtil.startPerformanceTest("Fix long indent/unindent "+time, time, new ThrowableRunnable() {
    @Override
    public void run() {
      EditorActionManager.getInstance().getActionHandler("EditorIndentSelection").execute(myEditor, DataManager.getInstance().getDataContext());

      EditorActionManager.getInstance().getActionHandler("EditorUnindentSelection").execute(myEditor, DataManager.getInstance().getDataContext());
    }
  }).assertTiming();
  final int startOffset = myEditor.getCaretModel().getOffset();
  myEditor.getSelectionModel().setSelection(startOffset,startOffset);
  checkResultByFile(getBasePath() + getTestName(false)+".xml");
}
项目:idea-gradle-dependencies-formatter    文件:MavenToGradleDependenciesCopyPasteProcessorTest.java   
private void runPasteAction(final String toPaste) {
    final Producer<Transferable> producer = new Producer<Transferable>() {
        @Nullable
        @Override
        public Transferable produce() {
            return new StringSelection(toPaste);
        }
    };
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler pasteActionHandler = actionManager.getActionHandler(ACTION_EDITOR_PASTE);
    final PasteHandler pasteHandler = new PasteHandler(pasteActionHandler);
    new WriteCommandAction.Simple(getProject(), new PsiFile[0]) {
        protected void run() throws Throwable {
            Component component = myFixture.getEditor().getComponent();
            DataContext dataContext = DataManager.getInstance().getDataContext(component);
            pasteHandler.execute(myFixture.getEditor(), dataContext, producer);
        }
    }.execute();
}
项目:power-mode-intellij-plugin    文件:PowerMode.java   
@Override
public void initComponent() {

    final EditorActionManager editorActionManager = EditorActionManager.getInstance();
    final EditorFactory editorFactory = EditorFactory.getInstance();
    particleContainerManager = new ParticleContainerManager();
    editorFactory.addEditorFactoryListener(particleContainerManager, new Disposable() {
        @Override
        public void dispose() {

        }
    });
    final TypedAction typedAction = editorActionManager.getTypedAction();
    final TypedActionHandler rawHandler = typedAction.getRawHandler();
    typedAction.setupRawHandler(new TypedActionHandler() {
        @Override
        public void execute(@NotNull final Editor editor, final char c, @NotNull final DataContext dataContext) {
            updateEditor(editor);
            rawHandler.execute(editor, c, dataContext);
        }
    });
}
项目:tools-idea    文件:BracesTailType.java   
@Override
public int processTail(final Editor editor, int tailOffset) {
  int startOffset = tailOffset;

  CharSequence seq = editor.getDocument().getCharsSequence();
  int nextNonWs = CharArrayUtil.shiftForward(seq, tailOffset, " \t");
  if (nextNonWs < seq.length() && seq.charAt(nextNonWs) == '{') {
    tailOffset = nextNonWs + 1;
  } else {
    tailOffset = insertChar(editor, startOffset, '{');
  }

  tailOffset = reformatBrace(editor, tailOffset, startOffset);

  if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, tailOffset, getFileType(editor))) {
    new EnterHandler(EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER))
      .executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
    return editor.getCaretModel().getOffset();
  }
  return tailOffset;
}
项目:tools-idea    文件:SelectionModelImpl.java   
@Override
public void selectWordAtCaret(boolean honorCamelWordsSettings) {
  validateContext(true);
  removeSelection();
  final EditorSettings settings = myEditor.getSettings();
  boolean camelTemp = settings.isCamelWords();

  final boolean needOverrideSetting = camelTemp && !honorCamelWordsSettings;
  if (needOverrideSetting) {
    settings.setCamelWords(false);
  }

  try {
    EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(
      IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
    handler.execute(myEditor, myEditor.getDataContext());
  }
  finally {
    if (needOverrideSetting) {
      settings.resetCamelWords();
    }
  }
}
项目:tools-idea    文件:SelectionQuotingTypedHandlerTest.java   
private void doTest(@NotNull final String cs, @NotNull String before, @NotNull String expected) {
  final boolean smarterSelection = Registry.is("editor.smarterSelectionQuoting");
  Registry.get("editor.smarterSelectionQuoting").setValue(true);
  try {
    myFixture.configureByText(FileTypes.PLAIN_TEXT, before);
    final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();

    performAction(myFixture.getProject(), new Runnable() {
      @Override
      public void run() {
        for (int i = 0, max = cs.length(); i < max; i++) {
          final char c = cs.charAt(i);
          typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
        }
      }
    });
    myFixture.checkResult(expected);
  } finally {
    Registry.get("editor.smarterSelectionQuoting").setValue(smarterSelection);
  }
}
项目:tools-idea    文件:SelectionQuotingTypedHandlerTest.java   
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(FileTypes.PLAIN_TEXT, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
项目:tools-idea    文件:CodeCompletionHandlerBase.java   
private static void addCompletionChar(Project project,
                                      CompletionAssertions.WatchingInsertionContext context,
                                      LookupElement item,
                                      Editor editor, CompletionProgressIndicator indicator, char completionChar) {
  int tailOffset = context.getTailOffset();
  if (tailOffset < 0) {
    LOG.info("tailOffset<0 after inserting " + item + " of " + item.getClass() + "; invalidated at: " + context.invalidateTrace + "\n--------");
  }
  else {
    editor.getCaretModel().moveToOffset(tailOffset);
  }
  if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
    final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    final List<SmartEnterProcessor> processors = SmartEnterProcessors.INSTANCE.forKey(language);
    if (processors.size() > 0) {
      for (SmartEnterProcessor processor : processors) {
        processor.process(project, editor, indicator.getParameters().getOriginalFile());
      }
    }
  }
  else {
    DataContext dataContext = DataManager.getInstance().getDataContext(editor.getContentComponent());
    EditorActionManager.getInstance().getTypedAction().getHandler().execute(editor, completionChar, dataContext);
  }
}
项目:consulo    文件:SelectionQuotingTypedHandlerTest.java   
private void doTest(@Nonnull final String cs, @Nonnull String before, @Nonnull String expected) {
  final boolean smarterSelection = Registry.is("editor.smarterSelectionQuoting");
  Registry.get("editor.smarterSelectionQuoting").setValue(true);
  try {
    myFixture.configureByText(PlainTextFileType.INSTANCE, before);
    final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();

    performAction(myFixture.getProject(), new Runnable() {
      @Override
      public void run() {
        for (int i = 0, max = cs.length(); i < max; i++) {
          final char c = cs.charAt(i);
          typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
        }
      }
    });
    myFixture.checkResult(expected);
  } finally {
    Registry.get("editor.smarterSelectionQuoting").setValue(smarterSelection);
  }
}
项目:consulo    文件:SelectionQuotingTypedHandlerTest.java   
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(PlainTextFileType.INSTANCE, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
项目:consulo    文件:HungryBackspaceAction.java   
@Override
public void executeWriteAction(@Nonnull Editor editor, Caret caret, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int caretOffset = editor.getCaretModel().getOffset();
  if (caretOffset < 1) {
    return;
  }

  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(caretOffset - 1);
  if (!selectionModel.hasSelection() && StringUtil.isWhiteSpace(c)) {
    int startOffset = CharArrayUtil.shiftBackward(text, caretOffset - 2, "\t \n") + 1;
    document.deleteString(startOffset, caretOffset);
  }
  else {
    final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
    handler.execute(editor, caret, dataContext);
  }
}
项目:consulo    文件:CaretImpl.java   
@Override
public void selectWordAtCaret(final boolean honorCamelWordsSettings) {
  validateContext(true);
  myEditor.getCaretModel().doWithCaretMerging(() -> {
    removeSelection();
    final EditorSettings settings = myEditor.getSettings();
    boolean camelTemp = settings.isCamelWords();

    final boolean needOverrideSetting = camelTemp && !honorCamelWordsSettings;
    if (needOverrideSetting) {
      settings.setCamelWords(false);
    }

    try {
      EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
      handler.execute(myEditor, this, myEditor.getDataContext());
    }
    finally {
      if (needOverrideSetting) {
        settings.resetCamelWords();
      }
    }
  });
}
项目:consulo    文件:CodeCompletionHandlerBase.java   
private static void addCompletionChar(Project project,
                                      CompletionAssertions.WatchingInsertionContext context,
                                      LookupElement item,
                                      Editor editor, CompletionProgressIndicator indicator, char completionChar) {
  if (!context.getOffsetMap().containsOffset(InsertionContext.TAIL_OFFSET)) {
    LOG.info("tailOffset<0 after inserting " + item + " of " + item.getClass() + "; invalidated at: " + context.invalidateTrace + "\n--------");
  }
  else {
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }
  if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
    final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language != null) {
      for (SmartEnterProcessor processor : SmartEnterProcessors.INSTANCE.forKey(language)) {
        if (processor.processAfterCompletion(editor, indicator.getParameters().getOriginalFile())) break;
      }
    }
  }
  else if (!editor.getCaretModel().supportsMultipleCarets()) { // this will be done outside of runForEach caret context
    DataContext dataContext = DataManager.getInstance().getDataContext(editor.getContentComponent());
    EditorActionManager.getInstance().getTypedAction().getHandler().execute(editor, completionChar, dataContext);
  }
}
项目:consulo    文件:FindUtil.java   
public static boolean replace(Project project, Editor editor, int offset, FindModel model, ReplaceDelegate delegate) {
  Document document = editor.getDocument();

  if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
    return false;
  }

  document.startGuardedBlockChecking();
  boolean toPrompt = model.isPromptOnReplace();

  try {
    doReplace(project, editor, model, document, offset, toPrompt, delegate);
  }
  catch (ReadOnlyFragmentModificationException e) {
    EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
  }
  finally {
    document.stopGuardedBlockChecking();
  }

  return true;
}
项目:consulo-java    文件:BracesTailType.java   
@Override
public int processTail(final Editor editor, int tailOffset) {
  int startOffset = tailOffset;

  CharSequence seq = editor.getDocument().getCharsSequence();
  int nextNonWs = CharArrayUtil.shiftForward(seq, tailOffset, " \t");
  if (nextNonWs < seq.length() && seq.charAt(nextNonWs) == '{') {
    tailOffset = nextNonWs + 1;
  } else {
    tailOffset = insertChar(editor, startOffset, '{');
  }

  tailOffset = reformatBrace(editor, tailOffset, startOffset);

  if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, tailOffset, getFileType(editor))) {
    new EnterHandler(EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER))
      .executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
    return editor.getCaretModel().getOffset();
  }
  return tailOffset;
}
项目:tmc-intellij    文件:StartupEvent.java   
private void setupHandlersForSpyware(ProgressObserver observer) {
    observer.progress(0, 0.70, "Setting handlers");
    final EditorActionManager actionManager = EditorActionManager.getInstance();
    final TypedAction typedAction = actionManager.getTypedAction();
    TypedActionHandler originalHandler = actionManager.getTypedAction().getHandler();
    typedAction.setupHandler(new ActivateSpywareAction(originalHandler));
}
项目:intellij-ce-playground    文件:LeaveCodeBlockEnterProcessor.java   
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
  PsiElement parent = psiElement.getParent();
  if (!(parent instanceof PsiCodeBlock)) {
    return false;
  }

  final ASTNode node = psiElement.getNode();
  if (node != null && CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType())) {
    return false;
  } 

  boolean leaveCodeBlock = isControlFlowBreak(psiElement);
  if (!leaveCodeBlock) {
    return false;
  }

  final int offset = parent.getTextRange().getEndOffset();

  // Check if there is empty line after the code block. Just move caret there in the case of the positive answer.
  final CharSequence text = editor.getDocument().getCharsSequence();
  if (offset < text.length() - 1) {
    final int i = CharArrayUtil.shiftForward(text, offset + 1, " \t");
    if (i < text.length() && text.charAt(i) == '\n') {
      editor.getCaretModel().moveToOffset(offset + 1);
      EditorActionManager actionManager = EditorActionManager.getInstance();
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
      final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
      if (dataContext != null) {
        actionHandler.execute(editor, dataContext);
        return true;
      }
    }
  }

  editor.getCaretModel().moveToOffset(offset);
  return false;
}
项目:intellij-ce-playground    文件:UnifiedDiffViewer.java   
private void installTypingSupport() {
  if (!isEditable(myMasterSide, false)) return;

  updateEditorCanBeTyped();
  myEditor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null); // guarded blocks
  EditorActionManager.getInstance().setReadonlyFragmentModificationHandler(myDocument, new MyReadonlyFragmentModificationHandler());
  myDocument.putUserData(UndoManager.ORIGINAL_DOCUMENT, getDocument(myMasterSide)); // use undo of master document

  myDocument.addDocumentListener(new MyOnesideDocumentListener());
}
项目:intellij-ce-playground    文件:LightPlatformCodeInsightTestCase.java   
public static void type(char c, @NotNull Editor editor, Project project) {
  if (c == '\n') {
    executeAction(IdeActions.ACTION_EDITOR_ENTER, editor,project);
  }
  else {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    final DataContext dataContext = DataManager.getInstance().getDataContext();
    TypedAction action = actionManager.getTypedAction();
    action.actionPerformed(editor, c, dataContext);
  }
}
项目:intellij-ce-playground    文件:TextComponentSelectionModel.java   
@Override
public void selectWordAtCaret(final boolean honorCamelWordsSettings) {
  removeSelection();

  EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(
    IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
  handler.execute(myEditor, DataManager.getInstance().getDataContext(myEditor.getComponent()));
}
项目:intellij-ce-playground    文件:CaretImpl.java   
@Override
public void selectWordAtCaret(final boolean honorCamelWordsSettings) {
  validateContext(true);
  myEditor.getCaretModel().doWithCaretMerging(new Runnable() {
    @Override
    public void run() {
      removeSelection();
      final EditorSettings settings = myEditor.getSettings();
      boolean camelTemp = settings.isCamelWords();

      final boolean needOverrideSetting = camelTemp && !honorCamelWordsSettings;
      if (needOverrideSetting) {
        settings.setCamelWords(false);
      }

      try {
        EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
        handler.execute(myEditor, CaretImpl.this, myEditor.getDataContext());
      }
      finally {
        if (needOverrideSetting) {
          settings.resetCamelWords();
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:ActionMacro.java   
public void playBack(DataContext context) {
  Editor editor = CommonDataKeys.EDITOR.getData(context);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  for (final char aChar : myText.toCharArray()) {
    typedAction.actionPerformed(editor, aChar, context);
  }
}
项目:intellij-ce-playground    文件:SelectionQuotingTypedHandlerTest.java   
private void doTest(@NotNull final String cs, @NotNull String before, @NotNull String expected) {
  myFixture.configureByText(FileTypes.PLAIN_TEXT, before);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();

  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      for (int i = 0, max = cs.length(); i < max; i++) {
        final char c = cs.charAt(i);
        typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
      }
    }
  });
  myFixture.checkResult(expected);
}
项目:intellij-ce-playground    文件:EditorLastActionTrackerTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  myTracker = EditorLastActionTracker.getInstance();
  mySavedHandler = EditorActionManager.getInstance().setActionHandler(SAMPLE_ACTION, myActionHandler);

  myFixture.configureByText(getTestName(true) + ".txt", "doesn't matter");
  myFixture.performEditorAction(SAMPLE_ACTION);
}
项目:intellij-ce-playground    文件:CCEditorFactoryListener.java   
@Override
public void editorCreated(@NotNull EditorFactoryEvent event) {
  Editor editor = event.getEditor();
  Project project = editor.getProject();
  if (project == null) {
    return;
  }
  VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
  if (virtualFile == null) {
    return;
  }
  final CCProjectService service = CCProjectService.getInstance(project);
  Course course = service.getCourse();
  if (course == null) {
    return;
  }
  final VirtualFile taskDir = virtualFile.getParent();
  if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
    return;
  }
  final VirtualFile lessonDir = taskDir.getParent();
  if (lessonDir == null) return;
  final TaskFile taskFile = service.getTaskFile(virtualFile);
  if (taskFile == null) {
    return;
  }
  EduDocumentListener listener = new EduDocumentListener(taskFile, true, true);
  CCProjectService.addDocumentListener(editor.getDocument(), listener);
  editor.getDocument().addDocumentListener(listener);
  EditorActionManager.getInstance()
    .setReadonlyFragmentModificationHandler(editor.getDocument(), new EduAnswerPlaceholderDeleteHandler(editor));
  service.drawAnswerPlaceholders(virtualFile, editor);
  editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
  EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false);
}
项目:intellij-ce-playground    文件:StudyUtils.java   
public static void drawAllWindows(Editor editor, TaskFile taskFile) {
  editor.getMarkupModel().removeAllHighlighters();
  final Project project = editor.getProject();
  if (project == null) return;
  final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
  for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
    final JBColor color = taskManager.getColor(answerPlaceholder);
    EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, true, color);
  }
  final Document document = editor.getDocument();
  EditorActionManager.getInstance()
    .setReadonlyFragmentModificationHandler(document, new EduAnswerPlaceholderDeleteHandler(editor));
  EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, true);
  editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
}
项目:PhpStorm    文件:SmartyTypedActionHandlerComponent.java   
/**
 * Replace the default key handling.
 */
public void initComponent ()
{
    EditorActionManager manager = EditorActionManager.getInstance();
    TypedAction action          = manager.getTypedAction();

    typed_handler = new SmartyTypedActionHandler(action.getHandler());
    action.setupHandler(typed_handler);
}
项目:PhpStorm    文件:SmartyTypedActionHandlerComponent.java   
/**
 * Restore the default key handling.
 */
public void disposeComponent ()
{
    EditorActionManager manager = EditorActionManager.getInstance();
    TypedAction action          = manager.getTypedAction();

    action.setupHandler(typed_handler.getOriginalTypedHandler());
}
项目:tools-idea    文件:CodeInsightTestCase.java   
protected static void type(char c, Editor editor) {
  EditorActionManager actionManager = EditorActionManager.getInstance();
  DataContext dataContext = DataManager.getInstance().getDataContext();
  if (c == '\n') {
    actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, dataContext);
    return;
  }
  TypedAction action = actionManager.getTypedAction();
  action.actionPerformed(editor, c, dataContext);
}
项目:tools-idea    文件:CodeInsightTestCase.java   
protected void backspace(final Editor editor) {
  CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
    @Override
    public void run() {
      EditorActionManager actionManager = EditorActionManager.getInstance();
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);

      actionHandler.execute(editor, DataManager.getInstance().getDataContext());
    }
  }, "backspace", editor.getDocument());
}
项目:tools-idea    文件:CodeInsightTestCase.java   
protected void delete(@NotNull final Editor editor) {
  CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
    @Override
    public void run() {
      EditorActionManager actionManager = EditorActionManager.getInstance();
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_DELETE);

      actionHandler.execute(editor, DataManager.getInstance().getDataContext());
    }
  }, "delete", editor.getDocument());
}