/** * 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; }
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); }
/** * Gets the number of actual lines in the file * * @param editor The editor * @return The file line count */ public static int getLineCount(@NotNull final Editor editor) { int len = editor.getDocument().getLineCount(); if (editor.getDocument().getTextLength() > 0 && editor.getDocument().getCharsSequence().charAt(editor.getDocument().getTextLength() - 1) == '\n') { len--; } return len; }
private static int getCompletionCharOffset(Editor editor) { int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence charsSequence = document.getCharsSequence(); char c; for (int i = startOffset; i < textLength; i++) { c = charsSequence.charAt(i); if (c == '(') { return i - startOffset; } else if (!Character.isSpaceChar(c)) { break; } } return -1; } }
private static boolean isCompletionCharAtSpace(Editor editor) { final int startOffset = editor.getCaretModel().getOffset(); final Document document = editor.getDocument(); return document.getTextLength() > startOffset && document.getCharsSequence().charAt(startOffset) == ':'; } }
private static int getCompletionCharOffset(Editor editor) { int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence charsSequence = document.getCharsSequence(); char c; for (int i = startOffset; i < textLength; i++) { c = charsSequence.charAt(i); if (c == ':') { return i - startOffset; } else if (!Character.isSpaceChar(c)) { break; } } return -1; } }
private static int getCompletionCharOffset(Editor editor) { int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence charsSequence = document.getCharsSequence(); char c; for (int i = startOffset; i < textLength; i++) { c = charsSequence.charAt(i); if (c == ':') { return i - startOffset; } else if (!Character.isSpaceChar(c)) { break; } } return -1; } }
private static int getCompletionCharOffset(Editor editor) { int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence charsSequence = document.getCharsSequence(); char c; for (int i = startOffset; i < textLength; i++) { c = charsSequence.charAt(i); if (c == '(') { return i - startOffset; } else if (!Character.isSpaceChar(c)) { break; } } return -1; } }
private static int getCompletionCharOffset(Editor editor) { int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence charsSequence = document.getCharsSequence(); char c; for (int i = startOffset; i < textLength; i++) { c = charsSequence.charAt(i); if (c == '(') { return i - startOffset; } else if (!Character.isSpaceChar(c)) { break; } } return -1; } }
private static int getCompletionCharOffset(Editor editor) { int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence charsSequence = document.getCharsSequence(); char c; for (int i = startOffset; i < textLength; i++) { c = charsSequence.charAt(i); if (c == '(') { return i - startOffset; } else if (!Character.isSpaceChar(c)) { break; } } return -1; } }
private int getStartOffset(@NotNull Editor editor, @NotNull Caret caret, SelectionType type, boolean beforeCursor) { if (beforeCursor) { return type == SelectionType.LINE_WISE ? VimPlugin.getMotion().moveCaretToLineStart(editor, caret) : caret.getOffset(); } int startOffset; if (type == SelectionType.LINE_WISE) { startOffset = Math.min(editor.getDocument().getTextLength(), VimPlugin.getMotion().moveCaretToLineEnd(editor, caret) + 1); if (startOffset > 0 && startOffset == editor.getDocument().getTextLength() && editor.getDocument().getCharsSequence().charAt(startOffset - 1) != '\n') { editor.getDocument().insertString(startOffset, "\n"); startOffset++; } } else { startOffset = caret.getOffset(); if (!EditorHelper.isLineEmpty(editor, caret.getLogicalPosition().line, false)) { startOffset++; } } if (startOffset > 0 && startOffset > editor.getDocument().getTextLength()) return startOffset - 1; return startOffset; }
/** * Sets new content to the editor component. * * @param content new content */ public void setContent(@NotNull final String content) { ApplicationManager.getApplication().runWriteAction( () -> CommandProcessor.getInstance().runUndoTransparentAction( () -> previewDocument.replaceString(0, previewDocument.getTextLength(), content) ) ); } }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); int tailOffset = context.getTailOffset(); Document document = editor.getDocument(); context.commitDocument(); boolean staysAtChar = document.getTextLength() > tailOffset && document.getCharsSequence().charAt(tailOffset) == myChar; context.setAddCompletionChar(false); if (!staysAtChar) { document.insertString(tailOffset, String.valueOf(myChar)); } editor.getCaretModel().moveToOffset(tailOffset + 1); AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(editor); } }
int offset = document.getTextLength();
final int line = lines.get(i); int startOffset = Math.min(editor.getDocument().getTextLength(), VimPlugin.getMotion().moveCaretToLineEnd(editor, line, true) + 1); if (startOffset > 0 && startOffset == editor.getDocument().getTextLength() && editor.getDocument().getCharsSequence().charAt(startOffset - 1) != '\n') { editor.getDocument().insertString(startOffset, "\n");
/** * Updates editor's content depending on the selected {@link TreePath}. * * @param path selected tree path */ private void updateDescriptionPanel(@NotNull TreePath path) { final TemplateTreeNode node = (TemplateTreeNode) path.getLastPathComponent(); final Resources.Template template = node.getTemplate(); ApplicationManager.getApplication().runWriteAction( () -> CommandProcessor.getInstance().runUndoTransparentAction(() -> { String content = template != null ? StringUtil.notNullize(template.getContent()).replace('\r', '\0') : ""; previewDocument.replaceString(0, previewDocument.getTextLength(), content); List<Pair<Integer, Integer>> pairs = getFilterRanges(profileFilter.getTextEditor().getText(), content); highlightWords(pairs); }) ); }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); int tailOffset = context.getTailOffset(); Document document = editor.getDocument(); context.commitDocument(); boolean staysAtChar = (document.getTextLength() > tailOffset) && (document.getCharsSequence().charAt(tailOffset) == myCharacter); context.setAddCompletionChar(false); if (!staysAtChar) { document.insertString(tailOffset, String.valueOf(myCharacter)); } editor.getCaretModel().moveToOffset(tailOffset + 1); AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(editor); } }
@Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { int tailOffset = context.getTailOffset(); Document document = context.getDocument(); int documentTextLength = document.getTextLength(); boolean insertParentheses; if (documentTextLength > tailOffset) { String currentTail = document.getText( new TextRange(tailOffset, tailOffset + 1) ); char firstChar = currentTail.charAt(0); insertParentheses = firstChar != ' ' && firstChar != '(' && firstChar != '['; } else { insertParentheses = true; } if (insertParentheses) { context.getDocument().insertString(tailOffset, "()"); // + 1 to put between the `(` and `)` context.getEditor().getCaretModel().moveToOffset(tailOffset + 1); } } }
public static void moveCaret(@NotNull Editor editor, @NotNull Caret caret, int offset, boolean forceKeepVisual) { if (offset >= 0 && offset <= editor.getDocument().getTextLength()) { final boolean keepVisual = forceKeepVisual || keepVisual(editor); if (caret.getOffset() != offset) { caret.moveToOffset(offset); CaretData.setLastColumn(editor, caret, caret.getVisualPosition().column); if (caret == editor.getCaretModel().getPrimaryCaret()) { scrollCaretIntoView(editor); } } if (keepVisual) { VimPlugin.getMotion().updateSelection(editor, caret, offset); } else { editor.getSelectionModel().removeSelection(); } } }
if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) { return;