com.intellij.openapi.editor.Editor.getDocument()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中com.intellij.openapi.editor.Editor.getDocument()方法的一些代码示例,展示了Editor.getDocument()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Editor.getDocument()方法的具体详情如下:
包路径:com.intellij.openapi.editor.Editor
类名称:Editor
方法名:getDocument

Editor.getDocument介绍

暂无

代码示例

代码示例来源:origin: JetBrains/ideavim

/***
 * @see :help visualmode()
 */
@Nullable
public static SelectionType getLastSelectionType(@NotNull Editor editor) {
 return editor.getDocument().getUserData(LAST_SELECTION_TYPE);
}

代码示例来源:origin: JetBrains/ideavim

/**
 * 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;
}

代码示例来源:origin: JetBrains/ideavim

@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;
}

代码示例来源:origin: JetBrains/ideavim

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);
}

代码示例来源:origin: JetBrains/ideavim

@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();
}

代码示例来源:origin: JetBrains/ideavim

@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);
}

代码示例来源:origin: JetBrains/ideavim

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;
}

代码示例来源:origin: JetBrains/ideavim

@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));
}

代码示例来源:origin: JetBrains/ideavim

public void displayHexInfo(@NotNull Editor editor) {
 int offset = editor.getCaretModel().getOffset();
 char ch = editor.getDocument().getCharsSequence().charAt(offset);
 VimPlugin.showMessage(Long.toHexString(ch));
}

代码示例来源:origin: JetBrains/ideavim

/**
 * 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);
}

代码示例来源:origin: JetBrains/ideavim

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);
}

代码示例来源:origin: JetBrains/ideavim

/**
 * 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);
}

代码示例来源:origin: JetBrains/ideavim

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);
}

代码示例来源:origin: JetBrains/ideavim

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));
}

代码示例来源:origin: JetBrains/ideavim

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);
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

@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();
  }
 }
};

代码示例来源:origin: JetBrains/ideavim

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);
 }
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

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));
 }
});

代码示例来源:origin: JetBrains/ideavim

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);
 }
}

代码示例来源:origin: JetBrains/ideavim

@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());

相关文章