private void setAnimatedScrolling(boolean isOn) { Editor[] editors = EditorFactory.getInstance().getAllEditors(); for (Editor editor : editors) { editor.getSettings().setAnimatedScrolling(isOn); } }
private void setRefrainFromScrolling(boolean isOn) { Editor[] editors = EditorFactory.getInstance().getAllEditors(); for (Editor editor : editors) { editor.getSettings().setRefrainFromScrolling(isOn); } }
private void setCursors(boolean isBlock) { Editor[] editors = EditorFactory.getInstance().getAllEditors(); for (Editor editor : editors) { // Vim plugin should be turned on in insert mode ((EditorEx)editor).setInsertMode(true); editor.getSettings().setBlockCursor(isBlock); } }
/** * This counts all the words in the file. */ @NotNull public static CountPosition countWords(@NotNull Editor editor, int start, int end) { CharSequence chars = editor.getDocument().getCharsSequence(); int offset = editor.getCaretModel().getOffset(); return countWords(chars, start, end, offset); }
private void deinitLineNumbers(@NotNull Editor editor) { editor.getCaretModel().removeCaretListener(myLineNumbersCaretListener); EditorData.setEditorGroup(editor, false); editor.getGutter().closeAllAnnotations(); final Project project = editor.getProject(); if (project == null || project.isDisposed()) return; editor.getSettings().setLineNumbersShown(EditorData.isLineNumbersShown(editor)); }
/** * Gets the visual block offset for the editor. * * @param editor The editor */ public static int getVisualBlockOffset(@NotNull Editor editor) { Integer visualBlockOffset = editor.getUserData(VISUAL_BLOCK_OFFSET); if (visualBlockOffset == null) { return editor.getCaretModel().getPrimaryCaret().getOffset(); } else { return visualBlockOffset; } }
/** * Clears all the keystrokes from the current insert command * * @param editor The editor to clear strokes from. */ private void clearStrokes(@NotNull Editor editor) { strokes.clear(); repeatCharsCount = 0; for (Caret caret : editor.getCaretModel().getAllCarets()) { CaretData.setInsertStart(caret, caret.getOffset()); } }
public static int findNextWord(@NotNull Editor editor, @NotNull Caret caret, int count, boolean bigWord) { CharSequence chars = editor.getDocument().getCharsSequence(); final int pos = caret.getOffset(); final int size = EditorHelper.getFileSize(editor); return findNextWord(chars, pos, size, count, bigWord, false); }
private void initLineNumbers(@NotNull final Editor editor) { editor.getCaretModel().addCaretListener(myLineNumbersCaretListener); EditorData.setEditorGroup(editor, true); final EditorSettings settings = editor.getSettings(); EditorData.setLineNumbersShown(editor, settings.isLineNumbersShown()); updateLineNumbers(editor); }
public void testUpDownMove() { final Editor editor = typeTextInFile(parseKeys("2j", "k"), "one\n" + "tw<caret>o\n" + "three\n" + "four\n"); final VisualPosition position = editor.getCaretModel().getVisualPosition(); assertEquals(new VisualPosition(2, 2), position); }
public static void setLastVisualRange(@NotNull Editor editor, @NotNull TextRange textRange) { editor.getDocument().putUserData(LAST_VISUAL_RANGE, textRange); }
@Override public void valueChange(OptionChangeEvent event) { for (Editor editor : EditorFactory.getInstance().getAllEditors()) { updateLineNumbers(editor); } } };
/** * Scrolls the editor to place the given visual line in the middle of the current window. * * @param editor The editor to scroll * @param visualLine The visual line to place in the middle of the current window */ public static void scrollVisualLineToMiddleOfScreen(@NotNull Editor editor, int visualLine) { final ScrollingModel scrollingModel = editor.getScrollingModel(); int y = editor.visualLineToY(visualLine); int lineHeight = editor.getLineHeight(); int height = scrollingModel.getVisibleArea().height; scrollingModel.scrollVertically(y - ((height - lineHeight) / 2)); }
public static int getVisualLineAtMiddleOfScreen(@NotNull final Editor editor) { final ScrollingModel scrollingModel = editor.getScrollingModel(); final Rectangle visibleArea = scrollingModel.getVisibleArea(); return editor.yToVisualLine(visibleArea.y + (visibleArea.height / 2)); }
public int moveCaretToColumn(@NotNull Editor editor, @NotNull Caret caret, int count, boolean allowEnd) { int line = caret.getLogicalPosition().line; int pos = EditorHelper.normalizeColumn(editor, line, count, allowEnd); return editor.logicalPositionToOffset(new LogicalPosition(line, pos)); }
public int moveCaretToLineEnd(@NotNull Editor editor, @NotNull Caret caret) { final VisualPosition visualPosition = caret.getVisualPosition(); final int lastVisualLineColumn = EditorUtil.getLastVisualLineColumnNumber(editor, visualPosition.line); final VisualPosition visualEndOfLine = new VisualPosition(visualPosition.line, lastVisualLineColumn, true); return moveCaretToLineEnd(editor, editor.visualToLogicalPosition(visualEndOfLine).line, true); }
private static int getHeightOfVisualLineInlays(@NotNull final Editor editor, int visualLine, boolean above) { InlayModel inlayModel = editor.getInlayModel(); List<Inlay> inlays = inlayModel.getBlockElementsForVisualLine(visualLine, above); int inlayHeight = 0; for (Inlay inlay : inlays) { inlayHeight += inlay.getHeightInPixels(); } return inlayHeight; } }
/** * Gets the visual block start for the editor. * * @param editor The editor */ public static int getVisualBlockStart(@NotNull Editor editor) { Integer visualBlockStart = editor.getUserData(VISUAL_BLOCK_START); if (visualBlockStart == null) { return editor.getCaretModel().getPrimaryCaret().getOffset(); } else { return visualBlockStart; } }
public void assertOffset(int... expectedOffsets) { final List<Caret> carets = myFixture.getEditor().getCaretModel().getAllCarets(); assertEquals("Wrong amount of carets", expectedOffsets.length, carets.size()); for (int i = 0; i < expectedOffsets.length; i++) { assertEquals(expectedOffsets[i], carets.get(i).getOffset()); } }
/** * Gets the visual block end for the editor. * * @param editor The editor */ public static int getVisualBlockEnd(@NotNull Editor editor) { Integer visualBlockEnd = editor.getUserData(VISUAL_BLOCK_END); if (visualBlockEnd == null) { return editor.getCaretModel().getPrimaryCaret().getOffset(); } else { return visualBlockEnd; } }