com.intellij.openapi.editor.actionSystem.EditorActionHandler Java Examples
The following examples show how to use
com.intellij.openapi.editor.actionSystem.EditorActionHandler.
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: CSharpEnterInDocLineCommentHandler.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override @RequiredUIAccess public Result preprocessEnter(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final Ref<Integer> caretOffsetRef, @Nonnull final Ref<Integer> caretAdvance, @Nonnull final DataContext dataContext, final EditorActionHandler originalHandler) { final int caretOffset = caretOffsetRef.get(); final Document document = editor.getDocument(); final PsiElement psiAtOffset = file.findElementAt(caretOffset); final PsiElement probablyDocComment = psiAtOffset instanceof PsiWhiteSpace && psiAtOffset.getText().startsWith("\n") ? psiAtOffset.getPrevSibling() : psiAtOffset == null && caretOffset > 0 && caretOffset == document.getTextLength() ? file.findElementAt(caretOffset - 1) : psiAtOffset; if(probablyDocComment != null && PsiTreeUtil.getParentOfType(probablyDocComment, CSharpDocRoot.class, false) != null) { document.insertString(caretOffset, DOC_LINE_START + " "); caretAdvance.set(4); return Result.Default; } return Result.Continue; }
Example #2
Source File: EnterHandler.java From bamboo-soy with Apache License 2.0 | 6 votes |
@Override public Result preprocessEnter( @NotNull PsiFile psiFile, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretOffsetChange, @NotNull DataContext dataContext, @Nullable EditorActionHandler originalHandler) { if (psiFile instanceof SoyFile && isBetweenSiblingTags(psiFile, caretOffset.get())) { if (originalHandler != null) { originalHandler.execute(editor, dataContext); } return Result.Default; } return Result.Continue; }
Example #3
Source File: EnterAfterUnmatchedBraceHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override public Result preprocessEnter(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final Ref<Integer> caretOffsetRef, @Nonnull final Ref<Integer> caretAdvance, @Nonnull final DataContext dataContext, final EditorActionHandler originalHandler) { int caretOffset = caretOffsetRef.get(); if (!isApplicable(file, caretOffset)) { return Result.Continue; } int maxRBraceCount = getMaxRBraceCount(file, editor, caretOffset); if (maxRBraceCount > 0) { insertRBraces(file, editor, caretOffset, getRBraceOffset(file, editor, caretOffset), generateStringToInsert(editor, caretOffset, maxRBraceCount)); return Result.DefaultForceIndent; } return Result.Continue; }
Example #4
Source File: DustEnterHandler.java From Intellij-Dust with MIT License | 6 votes |
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffset, @NotNull final Ref<Integer> caretAdvance, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) { /** * if we are between open and close tags, we ensure the caret ends up in the "logical" place on Enter. * i.e. "{#foo}<caret>{/foo}" becomes the following on Enter: * * {#foo} * <caret> * {/foo} * * (Note: <caret> may be indented depending on formatter settings.) */ if (file instanceof DustFile && isBetweenHbTags(editor, file, caretOffset.get())) { originalHandler.execute(editor, dataContext); return Result.Default; } return Result.Continue; }
Example #5
Source File: BashUnmatchedBraceEnterProcessor.java From BashSupport with Apache License 2.0 | 6 votes |
@Override public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, @Nullable EditorActionHandler originalHandler) { Project project = editor.getProject(); if (CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER && file instanceof BashFile && project != null) { Document document = editor.getDocument(); CharSequence chars = document.getCharsSequence(); int offset = caretOffset.get(); int length = chars.length(); if (offset < length && offset >= 1 && chars.charAt(offset - 1) == '{') { int start = offset + 1; int end = offset + 1 + "function".length(); if (start < length && end < length && "function".contentEquals(chars.subSequence(start, end))) { document.insertString(start, "\n"); PsiDocumentManager.getInstance(project).commitDocument(document); } } } return Result.Continue; }
Example #6
Source File: HungryBackspaceAction.java From consulo with Apache License 2.0 | 6 votes |
@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 #7
Source File: GraphQLEnterInEmptyListHandler.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffsetRef, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) { if (!file.getLanguage().is(GraphQLLanguage.INSTANCE)) { return Result.Continue; } return super.preprocessEnter(file, editor, caretOffsetRef, caretAdvance, dataContext, originalHandler); }
Example #8
Source File: EnterInLineCommentHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public Result preprocessEnter(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final Ref<Integer> caretOffsetRef, @Nonnull final Ref<Integer> caretAdvance, @Nonnull final DataContext dataContext, final EditorActionHandler originalHandler) { int caretOffset = caretOffsetRef.get().intValue(); PsiElement psiAtOffset = file.findElementAt(caretOffset); if (psiAtOffset != null && psiAtOffset.getTextOffset() < caretOffset) { ASTNode token = psiAtOffset.getNode(); Document document = editor.getDocument(); CharSequence text = document.getText(); final Language language = psiAtOffset.getLanguage(); final Commenter languageCommenter = LanguageCommenters.INSTANCE.forLanguage(language); final CodeDocumentationAwareCommenter commenter = languageCommenter instanceof CodeDocumentationAwareCommenter ? (CodeDocumentationAwareCommenter)languageCommenter:null; if (commenter != null && token.getElementType() == commenter.getLineCommentTokenType() ) { final int offset = CharArrayUtil.shiftForward(text, caretOffset, " \t"); if (offset < document.getTextLength() && text.charAt(offset) != '\n') { String prefix = commenter.getLineCommentPrefix(); assert prefix != null: "Line Comment type is set but Line Comment Prefix is null!"; if (!StringUtil.startsWith(text, offset, prefix)) { if (text.charAt(caretOffset) != ' ' && !prefix.endsWith(" ")) { prefix += " "; } document.insertString(caretOffset, prefix); return Result.Default; } } } } return Result.Continue; }
Example #9
Source File: EnterInStringLiteralHandler.java From BashSupport with Apache License 2.0 | 5 votes |
@Override public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, @Nullable EditorActionHandler originalHandler) { if (!(file instanceof BashFile)) { return Result.Continue; } int offset = caretOffset.get(); // don't wrap at EOL or EOF CharSequence content = editor.getDocument().getCharsSequence(); if (offset >= content.length() || content.charAt(offset) == '\n') { return Result.Continue; } if (PsiDocumentManager.getInstance(file.getProject()).isUncommited(editor.getDocument())) { // return early if PSI is not up-to-date to avoid blocking the editor // this might result in line-continuations not being inserted while editing return Result.Continue; } PsiElement psi = file.findElementAt(offset); if (psi == null || psi.getNode() == null) { return Result.Continue; } boolean isUserTyping = !Boolean.TRUE.equals(DataManager.getInstance().loadFromDataContext(dataContext, AutoHardWrapHandler.AUTO_WRAP_LINE_IN_PROGRESS_KEY)); if (isUserTyping && !isInString(psi)) { return Result.Continue; } if (offset >= psi.getTextOffset() && psi.getNode().getElementType() != BashTokenTypes.LINE_FEED) { EditorModificationUtil.insertStringAtCaret(editor, "\\\n"); return Result.Stop; } return Result.Continue; }
Example #10
Source File: EnterHandlerDelegateAdapter.java From consulo with Apache License 2.0 | 5 votes |
@Override public Result preprocessEnter(@Nonnull PsiFile file, @Nonnull Editor editor, @Nonnull Ref<Integer> caretOffset, @Nonnull Ref<Integer> caretAdvance, @Nonnull DataContext dataContext, EditorActionHandler originalHandler) { return Result.Continue; }
Example #11
Source File: BackspaceHandler.java From consulo with Apache License 2.0 | 5 votes |
static void truncatePrefix(final DataContext dataContext, LookupImpl lookup, final EditorActionHandler handler, final int hideOffset, final Caret caret) { final Editor editor = lookup.getEditor(); if (!lookup.performGuardedChange(() -> handler.execute(editor, caret, dataContext))) { return; } final CompletionProgressIndicator process = CompletionServiceImpl.getCurrentCompletionProgressIndicator(); lookup.truncatePrefix(process == null || !process.isAutopopupCompletion(), hideOffset); }
Example #12
Source File: BuildEnterBetweenBracketsHandler.java From intellij with Apache License 2.0 | 5 votes |
@Override public Result preprocessEnter( @NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffsetRef, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) { if (!(file instanceof BuildFile)) { return Result.Continue; } return super.preprocessEnter( file, editor, caretOffsetRef, caretAdvance, dataContext, originalHandler); }
Example #13
Source File: TextComponentSelectionModel.java From consulo with Apache License 2.0 | 5 votes |
@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 #14
Source File: ProjectViewEnterHandler.java From intellij with Apache License 2.0 | 5 votes |
@Override public Result preprocessEnter( PsiFile file, Editor editor, Ref<Integer> caretOffset, Ref<Integer> caretAdvance, DataContext dataContext, EditorActionHandler originalHandler) { int offset = caretOffset.get(); if (editor instanceof EditorWindow) { file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file); editor = InjectedLanguageUtil.getTopLevelEditor(editor); offset = editor.getCaretModel().getOffset(); } if (!isApplicable(file, dataContext) || !insertIndent(file, offset)) { return Result.Continue; } int indent = SectionParser.INDENT; editor.getCaretModel().moveToOffset(offset); Document doc = editor.getDocument(); PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc); originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext); LogicalPosition position = editor.getCaretModel().getLogicalPosition(); if (position.column < indent) { String spaces = StringUtil.repeatSymbol(' ', indent - position.column); doc.insertString(editor.getCaretModel().getOffset(), spaces); } editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent)); return Result.Stop; }
Example #15
Source File: LightPlatformCodeInsightTestCase.java From consulo with Apache License 2.0 | 5 votes |
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: TemplateLineEndHandler.java From consulo with Apache License 2.0 | 4 votes |
public TemplateLineEndHandler(final EditorActionHandler originalHandler) { super(originalHandler, false, false); }
Example #17
Source File: SelectAllHandler.java From consulo with Apache License 2.0 | 4 votes |
@Inject public SelectAllHandler(final EditorActionHandler originalHandler) { myOriginalHandler = originalHandler; }
Example #18
Source File: HomeHandler.java From consulo with Apache License 2.0 | 4 votes |
@Inject public HomeHandler(EditorActionHandler originalHandler){ myOriginalHandler = originalHandler; }
Example #19
Source File: TemplateLineEndWithSelectionHandler.java From consulo with Apache License 2.0 | 4 votes |
public TemplateLineEndWithSelectionHandler(final EditorActionHandler originalHandler) { super(originalHandler, false, true); }
Example #20
Source File: EscapeHandler.java From consulo with Apache License 2.0 | 4 votes |
public EscapeHandler(EditorActionHandler originalHandler) { myOriginalHandler = originalHandler; }
Example #21
Source File: EndHandler.java From consulo with Apache License 2.0 | 4 votes |
public EndHandler(EditorActionHandler originalHandler) { super(true); myOriginalHandler = originalHandler; }
Example #22
Source File: TemplateLineStartHandler.java From consulo with Apache License 2.0 | 4 votes |
public TemplateLineStartHandler(final EditorActionHandler originalHandler) { super(originalHandler, true, false); }
Example #23
Source File: JoinLinesHandler.java From consulo with Apache License 2.0 | 4 votes |
public JoinLinesHandler(EditorActionHandler originalHandler) { super(true); myOriginalHandler = originalHandler; }
Example #24
Source File: EnterHandler.java From consulo with Apache License 2.0 | 4 votes |
public EnterHandler(EditorActionHandler originalHandler) { super(true); myOriginalHandler = originalHandler; }
Example #25
Source File: CopyHandler.java From consulo with Apache License 2.0 | 4 votes |
@Inject public CopyHandler(final EditorActionHandler originalHandler) { myOriginalAction = originalHandler; }
Example #26
Source File: SelectWordHandler.java From consulo with Apache License 2.0 | 4 votes |
public SelectWordHandler(EditorActionHandler originalHandler) { super(true); myOriginalHandler = originalHandler; }
Example #27
Source File: CutHandler.java From consulo with Apache License 2.0 | 4 votes |
@Inject public CutHandler(EditorActionHandler originalHandler) { myOriginalHandler = originalHandler; }
Example #28
Source File: PasteHandler.java From consulo with Apache License 2.0 | 4 votes |
public PasteHandler(EditorActionHandler originalAction) { myOriginalHandler = originalAction; }
Example #29
Source File: BackspaceToWordStartHandler.java From consulo with Apache License 2.0 | 4 votes |
public BackspaceToWordStartHandler(EditorActionHandler originalHandler) { super(originalHandler); }
Example #30
Source File: BaseIndentEnterHandler.java From consulo with Apache License 2.0 | 4 votes |
@Override 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) { Result res = shouldSkipWithResult(file, editor, dataContext); if (res != null) { return res; } final Document document = editor.getDocument(); int caret = editor.getCaretModel().getOffset(); final int lineNumber = document.getLineNumber(caret); final int lineStartOffset = document.getLineStartOffset(lineNumber); final int previousLineStartOffset = lineNumber > 0 ? document.getLineStartOffset(lineNumber - 1) : lineStartOffset; final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); final HighlighterIterator iterator = highlighter.createIterator(caret - 1); final IElementType type = getNonWhitespaceElementType(iterator, lineStartOffset, previousLineStartOffset); final CharSequence editorCharSequence = document.getCharsSequence(); final CharSequence lineIndent = editorCharSequence.subSequence(lineStartOffset, EditorActionUtil.findFirstNonSpaceOffsetOnTheLine(document, lineNumber)); // Enter in line comment if (type == myLineCommentType) { final String restString = editorCharSequence.subSequence(caret, document.getLineEndOffset(lineNumber)).toString(); if (!StringUtil.isEmptyOrSpaces(restString)) { final String linePrefix = lineIndent + myLineCommentPrefix; EditorModificationUtil.insertStringAtCaret(editor, "\n" + linePrefix); editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, linePrefix.length())); return Result.Stop; } else if (iterator.getStart() < lineStartOffset) { EditorModificationUtil.insertStringAtCaret(editor, "\n" + lineIndent); return Result.Stop; } } if (!myWorksWithFormatter && LanguageFormatting.INSTANCE.forLanguage(myLanguage) != null) { return Result.Continue; } else { if (myIndentTokens.contains(type)) { final String newIndent = getNewIndent(file, document, lineIndent); EditorModificationUtil.insertStringAtCaret(editor, "\n" + newIndent); return Result.Stop; } EditorModificationUtil.insertStringAtCaret(editor, "\n" + lineIndent); editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, calcLogicalLength(editor, lineIndent))); return Result.Stop; } }