/*** * @see :help visualmode() */ @Nullable public static SelectionType getLastSelectionType(@NotNull Editor editor) { return editor.getDocument().getUserData(LAST_SELECTION_TYPE); }
/** * Gets the actual number of characters in the file * * @param editor The editor * @param includeEndNewLine True include newline * @return The file's character count */ public static int getFileSize(@NotNull final Editor editor, final boolean includeEndNewLine) { final int len = editor.getDocument().getTextLength(); return includeEndNewLine || len == 0 || editor.getDocument().getCharsSequence().charAt(len - 1) != '\n' ? len : len - 1; }
@NotNull public List<Mark> getMarks(@NotNull Editor editor) { HashSet<Mark> res = new HashSet<>(); final FileMarks<Character, Mark> marks = getFileMarks(editor.getDocument()); if (marks != null) { res.addAll(marks.values()); } res.addAll(globalMarks.values()); ArrayList<Mark> list = new ArrayList<>(res); list.sort(new Mark.KeySorter<>()); return list; }
public static int findUnmatchedBlock(@NotNull Editor editor, @NotNull Caret caret, char type, int count) { CharSequence chars = editor.getDocument().getCharsSequence(); int pos = caret.getOffset(); int loc = blockChars.indexOf(type); // What direction should we go now (-1 is backward, 1 is forward) int dir = loc % 2 == 0 ? -1 : 1; // Which character did we find and which should we now search for char match = blockChars.charAt(loc); char found = blockChars.charAt(loc - dir); return findBlockLocation(chars, found, match, dir, pos, count); }
@NotNull public static String getLeadingWhitespace(@NotNull final Editor editor, final int line) { int start = getLineStartOffset(editor, line); int end = getLeadingCharacterOffset(editor, line); return editor.getDocument().getCharsSequence().subSequence(start, end).toString(); }
@NotNull public static CharacterPosition offsetToCharacterPosition(@NotNull final Editor editor, final int offset) { int line = editor.getDocument().getLineNumber(normalizeOffset(editor, offset)); int col = offset - editor.getDocument().getLineStartOffset(line); return new CharacterPosition(line, col); }
public boolean executeFilter(@NotNull Editor editor, @NotNull TextRange range, @NotNull String command) throws IOException { final CharSequence charsSequence = editor.getDocument().getCharsSequence(); final int startOffset = range.getStartOffset(); final int endOffset = range.getEndOffset(); final String output = executeCommand(command, charsSequence.subSequence(startOffset, endOffset)); editor.getDocument().replaceString(startOffset, endOffset, output); return true; }
@NotNull public static CharBuffer getLineBuffer(@NotNull final Editor editor, final int line) { int start = getLineStartOffset(editor, line); return CharBuffer.wrap(editor.getDocument().getCharsSequence(), start, start + getLineCharCount(editor, line)); }
public void displayHexInfo(@NotNull Editor editor) { int offset = editor.getCaretModel().getOffset(); char ch = editor.getDocument().getCharsSequence().charAt(offset); VimPlugin.showMessage(Long.toHexString(ch)); }
/** * Gets the offset of the end of the line containing the supplied offset * * @param editor The editor * @param offset The offset within the line * @return The offset of the line end */ public static int getLineEndForOffset(@NotNull final Editor editor, final int offset) { LogicalPosition pos = editor.offsetToLogicalPosition(normalizeOffset(editor, offset)); return editor.getDocument().getLineEndOffset(pos.line); }
public static int normalizeOffset(@NotNull final Editor editor, int offset, final boolean allowEnd) { if (offset <= 0) { offset = 0; } final int textLength = editor.getDocument().getTextLength(); if (offset > textLength) { offset = textLength; } final int line = editor.offsetToLogicalPosition(offset).line; return normalizeOffset(editor, line, offset, allowEnd); }
/** * 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); }
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); }
public void displayAsciiInfo(@NotNull Editor editor) { int offset = editor.getCaretModel().getOffset(); char ch = editor.getDocument().getCharsSequence().charAt(offset); VimPlugin.showMessage("<" + StringHelper.toKeyNotation(KeyStroke.getKeyStroke(ch)) + "> " + (int)ch + ", Hex " + Long.toHexString(ch) + ", Octal " + Long.toOctalString(ch)); }
private int doIndent(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int startOffset, int endOffset) { final int startLine = editor.offsetToLogicalPosition(startOffset).line; final int endLine = editor.offsetToLogicalPosition(endOffset - 1).line; final int startLineOffset = editor.getDocument().getLineStartOffset(startLine); final int endLineOffset = editor.getDocument().getLineEndOffset(endLine); VimPlugin.getChange().autoIndentRange(editor, caret, context, new TextRange(startLineOffset, endLineOffset)); return EditorHelper.getLineEndOffset(editor, endLine, true); }
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { Document document = event.getEditor().getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null && file.getFileType() == GoFileType.INSTANCE) { checkForUpdates(); } } };
public void autoIndentLines(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count) { final int startLine = caret.getLogicalPosition().line; final int endLine = startLine + count - 1; if (endLine <= EditorHelper.getLineCount(editor)) { final TextRange range = new TextRange(caret.getOffset(), editor.getDocument().getLineEndOffset(endLine)); autoIndentRange(editor, caret, context, range); } }
private CompletionResultSet adjustMatcher(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result, @NotNull PsiElement parent) { int startOffset = parent.getTextRange().getStartOffset(); String newPrefix = parameters.getEditor().getDocument().getText(TextRange.create(startOffset, parameters.getOffset())); return result.withPrefixMatcher(createPrefixMatcher(newPrefix)); } });
private static void resetCursor(@NotNull Editor editor, boolean insert) { Document doc = editor.getDocument(); VirtualFile vf = FileDocumentManager.getInstance().getFile(doc); if (vf != null) { resetCursor(vf, editor.getProject(), insert); } else { editor.getSettings().setBlockCursor(!insert); } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); deinitLineNumbers(editor); EditorData.unInitializeEditor(editor); VimPlugin.getKey().unregisterShortcutKeys(editor); editor.getSettings().setAnimatedScrolling(isAnimatedScrolling); editor.getSettings().setRefrainFromScrolling(isRefrainFromScrolling); DocumentManager.getInstance().removeListeners(editor.getDocument()); } }, ApplicationManager.getApplication());