@Override public void adjustLineIndent(PsiFile file, TextRange rangeToAdjust) throws IncorrectOperationException { delegate.adjustLineIndent(file, rangeToAdjust); }
@Override public int adjustLineIndent(Document document, int offset) { return delegate.adjustLineIndent(document, offset); }
@Override public int adjustLineIndent(PsiFile file, int offset) throws IncorrectOperationException { return delegate.adjustLineIndent(file, offset); }
@Override public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { if (myOriginalHandler != null) myOriginalHandler.execute(editor, c, dataContext); if (c != 'e') return; Project project = editor.getProject(); if (project == null) return; int offset = editor.getCaretModel().getOffset(); if (offset < 4) return; TextRange from = TextRange.from(offset - 4, 4); String text = editor.getDocument().getText(from); if ("case".equals(text)) { PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); ApplicationManager.getApplication().runWriteAction(() -> { if (project.isDisposed()) return; PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); if (file == null) return; CodeStyleManager.getInstance(project).adjustLineIndent(file, from); }); } } }
CodeStyleManager.getInstance(context.getProject()).adjustLineIndent(document, offsetToMove);
private void doIndent(@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext, EditorActionHandler originalHandler, Document document) { originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext); PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); try { CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, editor.getCaretModel().getOffset()); } catch (IncorrectOperationException e) { LOG.error(e); } } }
@Override public boolean doEnter(PsiElement atCaret, PsiFile file, @NotNull Editor editor, boolean modified) { final CaretModel caretModel = editor.getCaretModel(); CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, caretModel.getOffset()); reformat(atCaret); commit(editor); if (atCaret instanceof FunctionCall && modified && file.isValid()) { return true; } if (atCaret instanceof CompoundExpression) { super.plainEnter(editor); return true; } if (atCaret instanceof PsiComment) { return true; } if (!(atCaret instanceof PsiFile)) { caretModel.moveToOffset(atCaret.getTextOffset() + atCaret.getTextLength()); } return true; } }
CodeStyleManager.getInstance(project).adjustLineIndent(editor.getDocument(), caretOffset.get() + 1);