List of usage examples for com.intellij.openapi.editor.actionSystem EditorActionHandler execute
@Deprecated public void execute(@NotNull Editor editor, @Nullable DataContext dataContext)
From source file:com.eightbitmage.moonscript.lang.MoonEnterHandlerDelegate.java
License:Apache License
@Override public Result preprocessEnter(PsiFile file, Editor editor, Ref<Integer> caretOffsetRef, Ref<Integer> caretAdvance, DataContext dataContext, EditorActionHandler originalHandler) { if (!(file instanceof MoonPsiFile)) return Result.Continue; Document document = editor.getDocument(); CharSequence text = document.getCharsSequence(); int caretOffset = caretOffsetRef.get(); PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); PsiElement e = file.findElementAt(caretOffset); PsiElement e1 = file.findElementAt(caretOffset - 1); // consume any whitespace until end of line looking for a token if (e != null) while (e instanceof PsiWhiteSpace || e instanceof MoonBlock) { if (e.getText().indexOf('\n') >= 0) break; e = e.getNextSibling();//from w w w . j a va 2 s.c om } // if e points to an end token, then insert a linefeed and indent the 'end' correctly if (e != null && e.getText().equals("end")) { if (text.charAt(caretOffset - 1) == '\n') editor.getCaretModel().moveToOffset(caretOffset - 1); try { CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, caretOffset); } catch (IncorrectOperationException ignored) { } PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); //originalHandler.execute(editor, dataContext); caretOffsetRef.set(editor.getCaretModel().getOffset()); return Result.DefaultForceIndent; } if (CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) { if (e1 != null) { if (e1.getText().equals("end") || e1.getText().equals("else") || e1.getText().equals("elseif") || e1.getText().equals("}") || e1.getText().equals("until")) { PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); try { CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, caretOffset - e1.getTextLength()); originalHandler.execute(editor, dataContext); } catch (IncorrectOperationException ignored) { } caretOffsetRef.set(editor.getCaretModel().getOffset()); return Result.Stop; } } } return Result.Continue; }
From source file:com.google.bamboo.soy.insight.typedhandlers.EnterHandler.java
License:Apache License
@Override public Result preprocessEnter(@Nonnull PsiFile psiFile, @Nonnull Editor editor, @Nonnull Ref<Integer> caretOffset, @Nonnull Ref<Integer> caretOffsetChange, @Nonnull DataContext dataContext, @Nullable EditorActionHandler originalHandler) { if (psiFile instanceof SoyFile && isBetweenSiblingTags(psiFile, caretOffset.get())) { if (originalHandler != null) { originalHandler.execute(editor, dataContext); }//from w ww .j a v a2s .c om return Result.Default; } return Result.Continue; }
From source file:com.intellij.codeInsight.CodeInsightTestCase.java
License:Apache License
protected void caretRight() { EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT); action.execute(getEditor(), DataManager.getInstance().getDataContext()); }
From source file:com.intellij.codeInsight.CodeInsightTestCase.java
License:Apache License
protected void caretUp() { EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP); action.execute(getEditor(), DataManager.getInstance().getDataContext()); }
From source file:com.intellij.codeInsight.CodeInsightTestCase.java
License:Apache License
protected void deleteLine() { EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_DELETE_LINE); action.execute(getEditor(), DataManager.getInstance().getDataContext()); }
From source file:com.intellij.codeInsight.CodeInsightTestCase.java
License:Apache License
protected void backspace(final Editor editor) { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override//from w ww.j av a 2 s. co m public void run() { EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler actionHandler = actionManager .getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE); actionHandler.execute(editor, DataManager.getInstance().getDataContext()); } }, "backspace", editor.getDocument()); }
From source file:com.intellij.codeInsight.CodeInsightTestCase.java
License:Apache License
protected void delete(@NotNull final Editor editor) { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override/*from w ww.j a v a 2 s . com*/ public void run() { EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_DELETE); actionHandler.execute(editor, DataManager.getInstance().getDataContext()); } }, "delete", editor.getDocument()); }
From source file:com.intellij.codeInsight.editorActions.enter.EnterAfterJavadocTagHandler.java
License:Apache License
@Override public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) { if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) { return Result.Continue; }//from www . j a v a2s. c om Document document = editor.getDocument(); CharSequence text = document.getCharsSequence(); int line = document.getLineNumber(caretOffset.get()); int start = document.getLineStartOffset(line); int end = document.getLineEndOffset(line); CodeDocumentationUtil.CommentContext commentContext = CodeDocumentationUtil.tryParseCommentContext(file, text, caretOffset.get(), start); if (!commentContext.docAsterisk) { return Result.Continue; } Context context = parse(text, start, end, caretOffset.get()); if (!context.shouldGenerateLine()) { return context.shouldIndent() ? Result.DefaultForceIndent : Result.Continue; } String indentInsideJavadoc = CodeDocumentationUtil.getIndentInsideJavadoc(document, caretOffset.get()); boolean restoreCaret = false; if (caretOffset.get() != context.endTagStartOffset) { editor.getCaretModel().moveToOffset(context.endTagStartOffset); restoreCaret = true; } originalHandler.execute(editor, dataContext); Project project = editor.getProject(); if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) { document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc); } if (restoreCaret) { editor.getCaretModel().moveToOffset(caretOffset.get()); } return Result.DefaultForceIndent; }
From source file:com.intellij.codeInsight.editorActions.enter.EnterBetweenBracesHandler.java
License:Apache License
@Override public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffsetRef, @NotNull final Ref<Integer> caretAdvance, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) { Document document = editor.getDocument(); CharSequence text = document.getCharsSequence(); int caretOffset = caretOffsetRef.get().intValue(); if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) { return Result.Continue; }// w w w . jav a 2 s .c o m if (caretOffset <= 0 || caretOffset >= text.length() || !isBracePair(text.charAt(caretOffset - 1), text.charAt(caretOffset))) { return Result.Continue; } final int line = document.getLineNumber(caretOffset); final int start = document.getLineStartOffset(line); final CodeDocumentationUtil.CommentContext commentContext = CodeDocumentationUtil .tryParseCommentContext(file, text, caretOffset, start); // special case: enter inside "()" or "{}" String indentInsideJavadoc = commentContext.docAsterisk ? CodeDocumentationUtil.getIndentInsideJavadoc(document, caretOffset) : null; originalHandler.execute(editor, dataContext); Project project = editor.getProject(); if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) { document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc); } PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); try { CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, editor.getCaretModel().getOffset()); } catch (IncorrectOperationException e) { LOG.error(e); } return indentInsideJavadoc == null ? Result.Continue : Result.DefaultForceIndent; }
From source file:com.intellij.codeInsight.editorActions.EnterBetweenXmlTagsHandler.java
License:Apache License
public Result preprocessEnter(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final Ref<Integer> caretOffset, @Nonnull final Ref<Integer> caretAdvance, @Nonnull final DataContext dataContext, final EditorActionHandler originalHandler) { final Project project = dataContext.getData(CommonDataKeys.PROJECT); if (file instanceof XmlFile && isBetweenXmlTags(project, editor, file, caretOffset.get().intValue())) { originalHandler.execute(editor, dataContext); return Result.DefaultForceIndent; }/* w w w . j a va 2s . co m*/ return Result.Continue; }