本文整理了Java中com.intellij.openapi.editor.Editor.getCaretModel()
方法的一些代码示例,展示了Editor.getCaretModel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Editor.getCaretModel()
方法的具体详情如下:
包路径:com.intellij.openapi.editor.Editor
类名称:Editor
方法名:getCaretModel
暂无
代码示例来源:origin: JetBrains/ideavim
public List<Integer> getOrderedLines(@NotNull Editor editor, @NotNull DataContext context,
@NotNull CaretOrder caretOrder) {
final ArrayList<Integer> lines = new ArrayList<>(editor.getCaretModel().getCaretCount());
for (Caret caret : EditorHelper.getOrderedCaretsList(editor, caretOrder)) {
final int line = getLine(editor, caret, context);
lines.add(line);
}
return lines;
}
代码示例来源:origin: JetBrains/ideavim
/**
* @deprecated To move the caret, use {@link #moveCaretToLineStartSkipLeading(Editor, Caret)}
*/
public int moveCaretToLineStartSkipLeading(@NotNull Editor editor) {
return moveCaretToLineStartSkipLeading(editor, editor.getCaretModel().getPrimaryCaret());
}
代码示例来源:origin: JetBrains/ideavim
/**
* @deprecated Use {@link #findNextParagraphLine(Editor, Caret, int, boolean)}
*/
public static int findNextSentenceStart(@NotNull Editor editor, int count, boolean countCurrent, boolean requireAll) {
return findNextSentenceStart(editor, editor.getCaretModel().getPrimaryCaret(), count, countCurrent, requireAll);
}
代码示例来源:origin: JetBrains/ideavim
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, int count, int rawCount,
@Nullable Argument argument) throws ExecuteMethodNotOverriddenException {
if (!myIsMulticaretChangeAction) {
throw new ExecuteMethodNotOverriddenException(this.getClass());
}
return execute(editor, editor.getCaretModel().getPrimaryCaret(), context, count, rawCount, argument);
}
代码示例来源:origin: JetBrains/ideavim
/**
* This gets the last column the primary cursor was in for the editor.
*
* @param editor The editor to get the last column from
* @return Returns the last column as set by {@link #setLastColumn} or the current primary cursor column
* @deprecated Use {@link CaretData#getLastColumn(Caret)} to get the primary cursor last column
*/
public static int getLastColumn(@NotNull Editor editor) {
return CaretData.getLastColumn(editor.getCaretModel().getPrimaryCaret());
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
GoLiveTemplateContextType.File fileContextType =
TemplateContextType.EP_NAME.findExtension(GoLiveTemplateContextType.File.class);
return fileContextType != null && fileContextType.isInContext(file, editor.getCaretModel().getOffset());
}
代码示例来源:origin: JetBrains/ideavim
public int moveCaretGotoNextTab(@NotNull Editor editor, @NotNull DataContext context, int rawCount) {
final boolean absolute = rawCount >= 1;
switchEditorTab(EditorWindow.DATA_KEY.getData(context), absolute ? rawCount - 1 : 1, absolute);
return editor.getCaretModel().getOffset();
}
代码示例来源:origin: JetBrains/ideavim
private int getRelativeLineNumber(int line, @NotNull Editor editor) {
final int visualLine = EditorHelper.logicalLineToVisualLine(editor, line);
final int currentLine = editor.getCaretModel().getLogicalPosition().line;
final int currentVisualLine = EditorHelper.logicalLineToVisualLine(editor, currentLine);
return Math.abs(currentVisualLine - visualLine);
}
代码示例来源:origin: JetBrains/ideavim
/**
* 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());
}
}
代码示例来源:origin: JetBrains/ideavim
/**
* Begin insert before the start of the current line
*
* @param editor The editor to insert into
* @param context The data context
*/
public void insertLineStart(@NotNull Editor editor, @NotNull DataContext context) {
for (Caret caret : editor.getCaretModel().getAllCarets()) {
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineStart(editor, caret));
}
initInsert(editor, context, CommandState.Mode.INSERT);
}
代码示例来源:origin: JetBrains/ideavim
public boolean scrollColumn(@NotNull Editor editor, int columns) {
int visualColumn = EditorHelper.getVisualColumnAtLeftOfScreen(editor);
visualColumn = EditorHelper
.normalizeVisualColumn(editor, editor.getCaretModel().getVisualPosition().line, visualColumn + columns, false);
scrollColumnToLeftOfScreen(editor, visualColumn);
moveCaretToView(editor);
return true;
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Override
public boolean doEnter(PsiElement psiElement, PsiFile file, @NotNull Editor editor, boolean modified) {
GoBlock block = findBlock(psiElement);
if (block != null) {
editor.getCaretModel().moveToOffset(block.getLbrace().getTextRange().getEndOffset());
}
plainEnter(editor);
return true;
}
}
代码示例来源:origin: JetBrains/ideavim
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);
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Nullable
private static GoExpression findExpressionAtOffset(GoIntroduceOperation operation) {
PsiFile file = operation.getFile();
int offset = operation.getEditor().getCaretModel().getOffset();
GoExpression expr = PsiTreeUtil.getNonStrictParentOfType(file.findElementAt(offset), GoExpression.class);
GoExpression preExpr = PsiTreeUtil.getNonStrictParentOfType(file.findElementAt(offset - 1), GoExpression.class);
if (expr == null || preExpr != null && PsiTreeUtil.isAncestor(expr, preExpr, false)) return preExpr;
return expr;
}
代码示例来源:origin: JetBrains/ideavim
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));
}
代码示例来源:origin: JetBrains/ideavim
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());
}
}
代码示例来源:origin: JetBrains/ideavim
public void testWrongYankRegisterMotion() {
final Editor editor = typeTextInFile(parseKeys("y\"", "0"),
"one <caret>two\n" +
"three\n" +
"four\n");
assertEquals(0, editor.getCaretModel().getOffset());
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private <T extends GoExpression> void doTest(@NotNull String text, @NotNull Class<T> aClass, int expected) {
myFixture.configureByText("a.go", text);
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
T callExpr = PsiTreeUtil.getParentOfType(element, aClass);
assertEquals(expected, GoInspectionUtil.getExpressionResultCount(callExpr));
}
代码示例来源:origin: JetBrains/ideavim
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);
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private void doTest(@NotNull String text, String expected) {
myFixture.configureByText("a.go", "package a\n" + text);
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
GoType type = PsiTreeUtil.getParentOfType(element, GoType.class);
assertNotNull(type);
assertEquals(expected, type.getUnderlyingType().getText());
}
内容来源于网络,如有侵权,请联系作者删除!