com.intellij.openapi.editor.actionSystem.EditorActionManager Java Examples

The following examples show how to use com.intellij.openapi.editor.actionSystem.EditorActionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HungryBackspaceAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
@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);
  }
}
 
Example #2
Source File: FindUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: SelectionQuotingTypedHandlerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #4
Source File: SelectionQuotingTypedHandlerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #5
Source File: JumpHandler.java    From KJump with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void stop() {
    if (isStart) {
        isStart = false;
        EditorActionManager manager = EditorActionManager.getInstance();
        manager.getTypedAction().setupRawHandler(mOldTypedHandler);
        if (mOldEscActionHandler != null) {
            manager.setActionHandler(IdeActions.ACTION_EDITOR_ESCAPE, mOldEscActionHandler);
        }

        Container parent = mMarksCanvas.getParent();
        if (parent != null) {
            parent.remove(mMarksCanvas);
            parent.repaint();
        }

        isCanvasAdded = false;
    }
}
 
Example #6
Source File: PowerMode.java    From power-mode-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example #7
Source File: ExpressionOrStatementInsertHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredWriteAction
public void handleInsert(final InsertionContext context, final T item)
{
	final Editor editor = context.getEditor();
	final Document document = editor.getDocument();
	context.commitDocument();

	handleInsertImpl(context, item, editor, document);

	if(myOpenChar == '{')
	{
		document.insertString(editor.getCaretModel().getOffset(), "\n");
	}

	context.commitDocument();

	PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset());
	PsiElement parent = elementAt == null ? null : elementAt.getParent();
	if(parent != null)
	{
		CodeStyleManager.getInstance(parent.getProject()).reformat(parent);

		if(myOpenChar == '{')
		{
			EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
			actionHandler.executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
		}
	}
}
 
Example #8
Source File: CodeCompletionHandlerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void addCompletionChar(InsertionContext context, LookupElement item) {
  if (!context.getOffsetMap().containsOffset(InsertionContext.TAIL_OFFSET)) {
    String message = "tailOffset<0 after inserting " + item + " of " + item.getClass();
    if (context instanceof WatchingInsertionContext) {
      message += "; invalidated at: " + ((WatchingInsertionContext)context).invalidateTrace + "\n--------";
    }
    LOG.info(message);
  }
  else if (!CompletionAssertions.isEditorValid(context.getEditor())) {
    LOG.info("Injected editor invalidated " + context.getEditor());
  }
  else {
    context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
  }
  if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
    Language language = PsiUtilBase.getLanguageInEditor(context.getEditor(), context.getFile().getProject());
    if (language != null) {
      for (SmartEnterProcessor processor : SmartEnterProcessors.INSTANCE.allForLanguage(language)) {
        if (processor.processAfterCompletion(context.getEditor(), context.getFile())) break;
      }
    }
  }
  else {
    DataContext dataContext = DataManager.getInstance().getDataContext(context.getEditor().getContentComponent());
    EditorActionManager.getInstance().getTypedAction().getHandler().execute(context.getEditor(), context.getCompletionChar(), dataContext);
  }
}
 
Example #9
Source File: ActionMacro.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void playBack(DataContext context) {
  Editor editor = context.getData(PlatformDataKeys.EDITOR);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  for (final char aChar : myText.toCharArray()) {
    typedAction.actionPerformed(editor, aChar, context);
  }
}
 
Example #10
Source File: EditorComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/** Inserts, removes or replaces the given text at the given offset */
private void editDocumentSafely(final int offset, final int length, @Nullable final String text) {
  final Project project = myEditor.getProject();
  final Document document = myEditor.getDocument();
  if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
    return;
  }
  CommandProcessor.getInstance().executeCommand(project,
                                                () -> ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(document, project) {
                                                  @Override
                                                  public void run() {
                                                    document.startGuardedBlockChecking();
                                                    try {
                                                      if (text == null) {
                                                        // remove
                                                        document.deleteString(offset, offset + length);
                                                      } else if (length == 0) {
                                                        // insert
                                                        document.insertString(offset, text);
                                                      } else {
                                                        document.replaceString(offset, offset + length, text);
                                                      }
                                                    }
                                                    catch (ReadOnlyFragmentModificationException e) {
                                                      EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
                                                    }
                                                    finally {
                                                      document.stopGuardedBlockChecking();
                                                    }
                                                  }
                                                }), "", document, UndoConfirmationPolicy.DEFAULT, document);
}
 
Example #11
Source File: TextComponentSelectionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void selectWordAtCaret(final boolean honorCamelWordsSettings) {
  removeSelection();

  EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(
          IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
  handler.execute(myEditor, null, DataManager.getInstance().getDataContext(myEditor.getComponent()));
}
 
Example #12
Source File: StartupEvent.java    From tmc-intellij with MIT License 5 votes vote down vote up
private void setupHandlersForSnapshots(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 ActivateSnapshotsAction(originalHandler));
}
 
Example #13
Source File: SelectionQuotingTypedHandlerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doTest(final char c, @Nonnull String before, @Nonnull String expected) {
  myFixture.configureByText(PlainTextFileType.INSTANCE, before);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult(expected);
}
 
Example #14
Source File: LightPlatformCodeInsightTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void type(char c) {
  EditorActionManager actionManager = EditorActionManager.getInstance();
  final DataContext dataContext = DataManager.getInstance().getDataContext();
  if (c == '\n') {
    actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(getEditor(), dataContext);
  }
  else if (c == '\b') {
    actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE).execute(getEditor(), dataContext);
  }
  else {
    actionManager.getTypedAction().actionPerformed(getEditor(), c, dataContext);
  }
}
 
Example #15
Source File: LightPlatformCodeInsightTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void executeAction(@NonNls @Nonnull final String actionId) {
  CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
    @Override
    public void run() {
      EditorActionManager actionManager = EditorActionManager.getInstance();
      EditorActionHandler actionHandler = actionManager.getActionHandler(actionId);
      actionHandler.execute(getEditor(), null, DataManager.getInstance().getDataContext());
    }
  }, "", null);
}
 
Example #16
Source File: UnifiedDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #17
Source File: CSharpAccessorCompletionContributor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, psiElement().andNot(psiElement().inside(DotNetXAccessor.class)), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@Nonnull CompletionParameters completionParameters, ProcessingContext processingContext, @Nonnull CompletionResultSet resultSet)
		{
			PsiElement position = completionParameters.getPosition();
			final CSharpXAccessorOwner accessorOwner = PsiTreeUtil.getParentOfType(position, CSharpXAccessorOwner.class);
			if(accessorOwner == null)
			{
				return;
			}
			PsiElement leftBrace = accessorOwner.getLeftBrace();
			if(leftBrace == null)
			{
				return;
			}

			int textOffset = position.getTextOffset();
			PsiElement rightBrace = accessorOwner.getRightBrace();
			int rightTextRange = rightBrace == null ? -1 : rightBrace.getTextOffset();

			if((rightTextRange == -1 || textOffset < rightTextRange) && textOffset > leftBrace.getTextOffset())
			{
				if(accessorOwner.hasModifier(DotNetModifier.ABSTRACT))
				{
					buildAccessorKeywordsCompletion(resultSet, accessorOwner, null);
				}
				else
				{
					buildAccessorKeywordsCompletion(resultSet, accessorOwner, new InsertHandler<LookupElement>()
					{
						@Override
						@RequiredWriteAction
						public void handleInsert(InsertionContext context, LookupElement item)
						{
							if(context.getCompletionChar() == '{')
							{
								context.setAddCompletionChar(false);

								Editor editor = context.getEditor();

								CaretModel caretModel = editor.getCaretModel();
								int offset = caretModel.getOffset();

								context.getDocument().insertString(offset, "{\n}");
								caretModel.moveToOffset(offset + 1);

								PsiElement elementAt = context.getFile().findElementAt(offset - 1);

								context.commitDocument();

								DotNetXAccessor accessor = PsiTreeUtil.getParentOfType(elementAt, DotNetXAccessor.class);
								if(accessor != null)
								{
									CodeStyleManager.getInstance(context.getProject()).reformat(accessor);
								}

								EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
								actionHandler.executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
							}
						}
					});
				}
			}
		}
	});
}
 
Example #18
Source File: CodeFormatterFacade.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Emulates pressing {@code Enter} at current caret position.
 *
 * @param editor  target editor
 * @param project target project
 * @param shifts  two-elements array which is expected to be filled with the following info:
 *                1. The first element holds added lines number;
 *                2. The second element holds added symbols number;
 */
private static void emulateEnter(@Nonnull final Editor editor, @Nonnull Project project, int[] shifts) {
  final DataContext dataContext = prepareContext(editor.getComponent(), project);
  int caretOffset = editor.getCaretModel().getOffset();
  Document document = editor.getDocument();
  SelectionModel selectionModel = editor.getSelectionModel();
  int startSelectionOffset = 0;
  int endSelectionOffset = 0;
  boolean restoreSelection = selectionModel.hasSelection();
  if (restoreSelection) {
    startSelectionOffset = selectionModel.getSelectionStart();
    endSelectionOffset = selectionModel.getSelectionEnd();
    selectionModel.removeSelection();
  }
  int textLengthBeforeWrap = document.getTextLength();
  int lineCountBeforeWrap = document.getLineCount();

  DataManager.getInstance().saveInDataContext(dataContext, WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY, true);
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  try {
    Runnable command = () -> EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, dataContext);
    if (commandProcessor.getCurrentCommand() == null) {
      commandProcessor.executeCommand(editor.getProject(), command, WRAP_LINE_COMMAND_NAME, null);
    }
    else {
      command.run();
    }
  }
  finally {
    DataManager.getInstance().saveInDataContext(dataContext, WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY, null);
  }
  int symbolsDiff = document.getTextLength() - textLengthBeforeWrap;
  if (restoreSelection) {
    int newSelectionStart = startSelectionOffset;
    int newSelectionEnd = endSelectionOffset;
    if (startSelectionOffset >= caretOffset) {
      newSelectionStart += symbolsDiff;
    }
    if (endSelectionOffset >= caretOffset) {
      newSelectionEnd += symbolsDiff;
    }
    selectionModel.setSelection(newSelectionStart, newSelectionEnd);
  }
  shifts[0] = document.getLineCount() - lineCountBeforeWrap;
  shifts[1] = symbolsDiff;
}
 
Example #19
Source File: SmartEnterProcessorWithFixers.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static EditorActionHandler getEnterHandler() {
  return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE);
}
 
Example #20
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static EditorActionHandler getDefaultActionHandler() {
  return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
}
 
Example #21
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static EditorActionHandler getDefaultActionHandler() {
  return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
}
 
Example #22
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static synchronized void initTypedHandler() {
  if (ourTypedHandlerInitialized) return;
  TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  typedAction.setupHandler(new MyTypedHandler(typedAction.getHandler()));
  ourTypedHandlerInitialized = true;
}
 
Example #23
Source File: PasteHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer<Transferable> producer) {
  final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer);
  if (transferable == null) return;

  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;

  final Document document = editor.getDocument();
  if (!FileDocumentManager.getInstance().requestWriting(document, dataContext.getData(CommonDataKeys.PROJECT))) {
    return;
  }

  DataContext context = new DataContext() {
    @Override
    public Object getData(@NonNls Key dataId) {
      return PasteAction.TRANSFERABLE_PROVIDER == dataId ? new Producer<Transferable>() {
        @Nullable
        @Override
        public Transferable produce() {
          return transferable;
        }
      } : dataContext.getData(dataId);
    }
  };

  final Project project = editor.getProject();
  if (project == null || editor.isColumnMode() || editor.getCaretModel().getCaretCount() > 1) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, null, context);
    }
    return;
  }

  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (file == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, null, context);
    }
    return;
  }

  DumbService.getInstance(project).setAlternativeResolveEnabled(true);
  document.startGuardedBlockChecking();
  try {
    for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) {
      if (provider.isPasteEnabled(context)) {
        provider.performPaste(context);
        return;
      }
    }
    doPaste(editor, project, file, document, transferable);
  }
  catch (ReadOnlyFragmentModificationException e) {
    EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
  }
  finally {
    document.stopGuardedBlockChecking();
    DumbService.getInstance(project).setAlternativeResolveEnabled(false);
  }
}
 
Example #24
Source File: SmartEnterAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static EditorActionHandler getEnterHandler() {
  return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE);
}
 
Example #25
Source File: SmartEnterAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null || editor.isOneLineMode()) {
    plainEnter(editor, caret, dataContext);
    return;
  }

  LookupManager.getInstance(project).hideActiveLookup();

  TemplateState state = TemplateManagerImpl.getTemplateState(editor);
  if (state != null) {
    state.gotoEnd();
  }

  final int caretOffset = editor.getCaretModel().getOffset();

  PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) {
    plainEnter(editor, caret, dataContext);
    return;
  }

  if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, caretOffset, psiFile.getFileType())) {
    EditorActionHandler enterHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
    enterHandler.execute(editor, caret, dataContext);
    return;
  }

  final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
  boolean processed = false;
  if (language != null) {
    final List<SmartEnterProcessor> processors = SmartEnterProcessors.INSTANCE.allForLanguage(language);
    if (!processors.isEmpty()) {
      for (SmartEnterProcessor processor : processors) {
        if (processor.process(project, editor, psiFile)) {
          processed = true;
          break;
        }
      }
    }
  }
  if (!processed) {
    plainEnter(editor, caret, dataContext);
  }
}
 
Example #26
Source File: EditorTestUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void performPaste(Editor editor) {
  EditorActionManager actionManager = EditorActionManager.getInstance();
  EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_PASTE);
  actionHandler.execute(editor, DataManager.getInstance().getDataContext());
}
 
Example #27
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void type(final char c) {
  assertInitialized();
  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      final EditorActionManager actionManager = EditorActionManager.getInstance();
      if (c == '\b') {
        performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE);
        return;
      }
      if (c == '\n') {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM)) {
          return;
        }

        performEditorAction(IdeActions.ACTION_EDITOR_ENTER);
        return;
      }
      if (c == '\t') {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_BY_TAB)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EDITOR_TAB)) {
          return;
        }
      }
      if (c == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)) {
          return;
        }
      }

      CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
          CommandProcessor.getInstance().setCurrentCommandGroupId(myEditor.getDocument());
          ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, getEditorDataContext());
          actionManager.getTypedAction().actionPerformed(getEditor(), c, getEditorDataContext());
        }
      }, null, DocCommandGroupId.noneGroupId(myEditor.getDocument()));
    }
  });
}
 
Example #28
Source File: StartNewLineBeforeAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static EditorActionHandler getHandler(@Nonnull String actionId) {
  return EditorActionManager.getInstance().getActionHandler(actionId);
}
 
Example #29
Source File: StartNewLineAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static EditorActionHandler getEnterHandler() {
  return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
}
 
Example #30
Source File: SplitLineAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static EditorActionHandler getEnterHandler() {
  return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
}