当前位置: 首页>>代码示例>>Java>>正文


Java CaretModel.getOffset方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.CaretModel.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java CaretModel.getOffset方法的具体用法?Java CaretModel.getOffset怎么用?Java CaretModel.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.CaretModel的用法示例。


在下文中一共展示了CaretModel.getOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findMatchingElement

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Nullable
PsiElement findMatchingElement(PsiFile file,
                               Editor editor) {
  final CaretModel caretModel = editor.getCaretModel();
  final int position = caretModel.getOffset();
  PsiElement element = file.findElementAt(position);
  while (element != null) {
     if (predicate.satisfiedBy(element)) {
      return element;
    } else {
      element = element.getParent();
      if (isStopElement(element)) {
        break;
      }
    }
  }
  return null;
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:19,代码来源:Intention.java

示例2: getSelectedMethod

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
private static PsiMethod getSelectedMethod(Editor editor, PsiFile file, DataContext dataContext) {
  final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
  PsiMethod selectedMethod = null;
  if (element instanceof PsiMethod) {
    selectedMethod = (PsiMethod)element;
  }
  else if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod){
    selectedMethod = (PsiMethod)((PsiParameter)element).getDeclarationScope();
  }
  else {
    final CaretModel caretModel = editor.getCaretModel();
    final int position = caretModel.getOffset();
    final PsiElement elementAt = file.findElementAt(position);
    final PsiMethodCallExpression methodCallExpression =
     PsiTreeUtil.getParentOfType(elementAt, PsiMethodCallExpression.class);
    if (methodCallExpression != null) {
      selectedMethod = methodCallExpression.resolveMethod();
    } else {
      final PsiParameterList parameterList = PsiTreeUtil.getParentOfType(elementAt, PsiParameterList.class);
      if (parameterList != null && parameterList.getParent() instanceof PsiMethod) {
        selectedMethod = (PsiMethod)parameterList.getParent();
      }
    }
  }
  return selectedMethod;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:IntroduceParameterObjectHandler.java

示例3: testUnexpectedClassLevelJavadocExpandingOnClassSignatureChange

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public void testUnexpectedClassLevelJavadocExpandingOnClassSignatureChange() throws IOException {
  // Inspired by IDEA-61275

  String text =
    "/**\n" +
    " * This is a test comment\n" +
    " */\n" +
    "public <caret>class Test {\n" +
    "}";
  init(text, TestFileType.JAVA);

  CaretModel caretModel = myEditor.getCaretModel();
  int caretOffset = caretModel.getOffset();
  
  assertEquals(caretOffset, caretModel.getOffset());

  updateFoldRegions();
  toggleFoldRegionState(getFoldRegion(0), false);
  type('a');
  updateFoldRegions();

  assertEquals(caretOffset + 1, caretModel.getOffset());
  assertEquals(1, myEditor.getFoldingModel().getAllFoldRegions().length);
  FoldRegion foldRegion = getFoldRegion(0);
  assertFalse(foldRegion.isExpanded());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:FoldingProcessingOnDocumentModificationTest.java

示例4: executeWriteAction

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  CaretModel caretModel = editor.getCaretModel();
  int caretOffset = caretModel.getOffset();
  if (caretOffset <= 0) {
    return;
  }

  boolean camel = editor.getSettings().isCamelWords();
  for (int i = caretOffset - 1; i >= 0; i--) {
    if (EditorActionUtil.isWordOrLexemeStart(editor, i, camel)) {
      KillRingUtil.cut(editor, i, caretOffset);
      return;
    }
  }

  KillRingUtil.cut(editor, 0, caretOffset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:KillToWordStartAction.java

示例5: getCaretShift

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
private static int getCaretShift(PsiElement startToMove, PsiElement endToMove, CaretModel caretModel, boolean selectionStartAtCaret) {
  int shift;
  if (selectionStartAtCaret) {
    shift = caretModel.getOffset() - startToMove.getTextRange().getStartOffset();
  }
  else {
    shift = caretModel.getOffset();
    if (startToMove != endToMove) {
      shift += startToMove.getTextLength();

      PsiElement tmp = startToMove.getNextSibling();
      while (tmp != endToMove && tmp != null) {
        if (!(tmp instanceof PsiWhiteSpace))
          shift += tmp.getTextLength();
        tmp = tmp.getNextSibling();
      }
    }

    shift -= endToMove.getTextOffset();
  }
  return shift;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PyStatementMover.java

示例6: actionPerformed

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    final Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    final int offset = caretModel.getOffset();
    new PopupChooserBuilder(QUERY_OPERATOR_LIST)
            .setMovable(false)
            .setCancelKeyEnabled(true)
            .setItemChoosenCallback(new Runnable() {
                public void run() {
                    final String selectedQueryOperator = (String) QUERY_OPERATOR_LIST.getSelectedValue();
                    if (selectedQueryOperator == null) return;

                    new WriteCommandAction(project, MONGO_OPERATOR_COMPLETION) {
                        @Override
                        protected void run(@NotNull Result result) throws Throwable {
                            document.insertString(offset, selectedQueryOperator);
                        }
                    }.execute();
                }
            })
            .createPopup()
            .showInBestPositionFor(editor);
}
 
开发者ID:dboissier,项目名称:nosql4idea,代码行数:25,代码来源:OperatorCompletionAction.java

示例7: executeWriteAction

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  CaretModel caretModel = editor.getCaretModel();
  int caretOffset = caretModel.getOffset();
  Document document = editor.getDocument();
  if (caretOffset <= 0) {
    return;
  }

  CharSequence text = document.getCharsSequence();
  boolean camel = editor.getSettings().isCamelWords();
  for (int i = caretOffset - 1; i >= 0; i--) {
    if (EditorActionUtil.isWordStart(text, i, camel)) {
      KillRingUtil.cut(editor, i, caretOffset);
      return;
    }
  }

  KillRingUtil.cut(editor, 0, caretOffset);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:KillToWordStartAction.java

示例8: execute

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
  if (!(editor instanceof EditorEx)) {
    return;
  }
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }
  
  EditorEx editorEx = (EditorEx)editor;
  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  final CaretModel caretModel = editor.getCaretModel();
  boolean moveToEnd = caretModel.getOffset() == start;
  editorEx.setStickySelection(false);
  editorEx.setStickySelection(true);
  if (moveToEnd) {
    caretModel.moveToOffset(end);
  }
  else {
    caretModel.moveToOffset(start);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:SwapSelectionBoundariesAction.java

示例9: findMatchingElement

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Nullable
PsiElement findMatchingElement(PsiFile file,
                               Editor editor) {
  final CaretModel caretModel = editor.getCaretModel();
  final int position = caretModel.getOffset();
  PsiElement element = file.findElementAt(position);
  while (element != null) {
    if (predicate.satisfiedBy(element)) {
      return element;
    } else {
      element = element.getParent();
      if (isStopElement(element)) {
        break;
      }
    }
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo-lua,代码行数:19,代码来源:Intention.java

示例10: executeWriteAction

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  CaretModel caretModel = editor.getCaretModel();
  int caretOffset = caretModel.getOffset();
  Document document = editor.getDocument();
  if (caretOffset <= 0) {
    return;
  }

  CharSequence text = document.getCharsSequence();
  boolean camel = editor.getSettings().isCamelWords();
  for (int i = caretOffset - 1; i >= 0; i--) {
    if (EditorActionUtil.isWordStart(text, i, camel)) {
      KillRingUtil.cut(editor, i, caretOffset);
      return;
    }
  }

  KillRingUtil.cut(editor, 0, caretOffset);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:KillToWordStartAction.java

示例11: execute

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
  if (!(editor instanceof EditorEx)) {
    return;
  }
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }

  EditorEx editorEx = (EditorEx)editor;
  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  final CaretModel caretModel = editor.getCaretModel();
  boolean moveToEnd = caretModel.getOffset() == start;
  editorEx.setStickySelection(false);
  editorEx.setStickySelection(true);
  if (moveToEnd) {
    caretModel.moveToOffset(end);
  }
  else {
    caretModel.moveToOffset(start);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:SwapSelectionBoundariesAction.java

示例12: findMatchingElement

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
@Nullable
public PsiElement findMatchingElement(PsiFile file, Editor editor)
{
	final CaretModel caretModel = editor.getCaretModel();
	final int position = caretModel.getOffset();
	PsiElement element = file.findElementAt(position);
	while(element != null)
	{
		if(predicate.satisfiedBy(element))
		{
			return element;
		}
		else
		{
			element = element.getParent();
		}
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-google-guice,代码行数:20,代码来源:Intention.java

示例13: testUnexpectedClassLevelJavadocExpandingOnClassSignatureChange

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public void testUnexpectedClassLevelJavadocExpandingOnClassSignatureChange() throws IOException
{
	// Inspired by IDEA-61275

	String text = "/**\n" + " * This is a test comment\n" + " */\n" + "public <caret>class Test {\n" + "}";
	init(text, TestFileType.JAVA);

	CaretModel caretModel = myEditor.getCaretModel();
	int caretOffset = caretModel.getOffset();

	assertEquals(caretOffset, caretModel.getOffset());

	updateFoldRegions();
	toggleFoldRegionState(getFoldRegion(0), false);
	type('a');
	updateFoldRegions();

	assertEquals(caretOffset + 1, caretModel.getOffset());
	assertEquals(1, myEditor.getFoldingModel().getAllFoldRegions().length);
	FoldRegion foldRegion = getFoldRegion(0);
	assertFalse(foldRegion.isExpanded());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:FoldingProcessingOnDocumentModificationTest.java

示例14: getCurrentWords

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
private String getCurrentWords(Editor editor) {
    Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    int lineNum = document.getLineNumber(caretOffset);
    int lineStartOffset = document.getLineStartOffset(lineNum);
    int lineEndOffset = document.getLineEndOffset(lineNum);
    String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
    char[] chars = lineContent.toCharArray();
    int start = 0, end = 0, cursor = caretOffset - lineStartOffset;

    if (!Character.isLetter(chars[cursor])) {
        return null;
    }

    for (int ptr = cursor; ptr >= 0; ptr--) {
        if (!Character.isLetter(chars[ptr])) {
            start = ptr + 1;
            break;
        }
    }

    int lastLetter = 0;
    for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
        lastLetter = ptr;
        if (!Character.isLetter(chars[ptr])) {
            end = ptr;
            break;
        }
    }
    if (end == 0) {
        end = lastLetter + 1;
    }

    return new String(chars, start, end - start);
}
 
开发者ID:a483210,项目名称:GoogleTranslation,代码行数:37,代码来源:GoogleTranslation.java

示例15: getCurrentWords

import com.intellij.openapi.editor.CaretModel; //导入方法依赖的package包/类
public String getCurrentWords(Editor editor) {
    Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    int lineNum = document.getLineNumber(caretOffset);
    int lineStartOffset = document.getLineStartOffset(lineNum);
    int lineEndOffset = document.getLineEndOffset(lineNum);
    String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
    char[] chars = lineContent.toCharArray();
    int start = 0, end = 0, cursor = caretOffset - lineStartOffset;

    if (!Character.isLetter(chars[cursor])) {
        Logger.warn("Caret not in a word");
        return null;
    }

    for (int ptr = cursor; ptr >= 0; ptr--) {
        if (!Character.isLetter(chars[ptr])) {
            start = ptr + 1;
            break;
        }
    }

    int lastLetter = 0;
    for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
        lastLetter = ptr;
        if (!Character.isLetter(chars[ptr])) {
            end = ptr;
            break;
        }
    }
    if (end == 0) {
        end = lastLetter + 1;
    }

    String ret = new String(chars, start, end-start);
    Logger.info("Selected words: " + ret);
    return ret;
}
 
开发者ID:BolexLiu,项目名称:ReciteWords,代码行数:40,代码来源:ReciteWords.java


注:本文中的com.intellij.openapi.editor.CaretModel.getOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。