當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.getLineEndOffset方法代碼示例

本文整理匯總了Java中com.intellij.openapi.editor.Document.getLineEndOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getLineEndOffset方法的具體用法?Java Document.getLineEndOffset怎麽用?Java Document.getLineEndOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.editor.Document的用法示例。


在下文中一共展示了Document.getLineEndOffset方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateGherkinRunIcons

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) {
    for (int i = 0; i < rootDocument.getLineCount(); i++) {
        int startOffset = rootDocument.getLineStartOffset(i);
        int endOffset = rootDocument.getLineEndOffset(i);

        String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim();

        Icon icon;
        if (lineText.matches(SCENARIO_REGEX)) {
            icon = GherkinIconRenderer.SCENARIO_ICON;
        } else if (lineText.matches(FEATURE_REGEX)) {
            icon = GherkinIconRenderer.FEATURE_ICON;
        } else {
            // System.out.println();
             continue;
        }
        GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName);
        gherkinIconRenderer.setLine(i);
        gherkinIconRenderer.setIcon(icon);

        RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes());
        rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer);
    }
}
 
開發者ID:KariiO,項目名稱:Gherkin-TS-Runner,代碼行數:25,代碼來源:GherkinIconUtils.java

示例2: createRangeHighlighter

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private RangeHighlighter createRangeHighlighter(Document document, Editor editor, int fromLine, int toLine, TextAttributes attributes) {
    int lineStartOffset = document.getLineStartOffset(Math.max(0, fromLine));
    int lineEndOffset = document.getLineEndOffset(Math.max(0, toLine));

    return editor.getMarkupModel().addRangeHighlighter(
            lineStartOffset, lineEndOffset, 3333, attributes, HighlighterTargetArea.LINES_IN_RANGE
    );
}
 
開發者ID:KariiO,項目名稱:Gherkin-TS-Runner,代碼行數:9,代碼來源:GherkinIconUtils.java

示例3: getCurrentWords

import com.intellij.openapi.editor.Document; //導入方法依賴的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

示例4: getCurrentWords

import com.intellij.openapi.editor.Document; //導入方法依賴的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

示例5: getWordAtCaretStart

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static int getWordAtCaretStart( Project project, String filePath )
{
  Editor[] editor = new Editor[1];
  editor[0] = getActiveEditor( project );
  if( !(editor[0] instanceof EditorImpl) )
  {
    return -1;
  }

  EditorImpl editorImpl = (EditorImpl)editor[0];
  if( !editorImpl.getVirtualFile().getPath().equals( filePath ) )
  {
    return -1;
  }

  CaretModel cm = editorImpl.getCaretModel();
  Document document = editorImpl.getDocument();
  int offset = cm.getOffset();
  if( offset == 0 )
  {
    return 0;
  }
  int lineNumber = cm.getLogicalPosition().line;
  int newOffset = offset - 1;
  int minOffset = lineNumber > 0 ? document.getLineEndOffset( lineNumber - 1 ) : 0;
  for( ; newOffset > minOffset; newOffset-- )
  {
    if( EditorActionUtil.isWordOrLexemeStart( editorImpl, newOffset, false ) )
    {
      break;
    }
  }

  return newOffset;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:36,代碼來源:ResourceToManifoldUtil.java

示例6: getWordAtCaretEnd

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static int getWordAtCaretEnd( Project project, String filePath )
{
  Editor[] editor = new Editor[1];
  editor[0] = getActiveEditor( project );
  if( !(editor[0] instanceof EditorImpl) )
  {
    return -1;
  }

  EditorImpl editorImpl = (EditorImpl)editor[0];
  if( !editorImpl.getVirtualFile().getPath().equals( filePath ) )
  {
    return -1;
  }

  CaretModel cm = editorImpl.getCaretModel();
  Document document = editorImpl.getDocument();
  int offset = cm.getOffset();

  if( offset >= document.getTextLength() - 1 || document.getLineCount() == 0 )
  {
    return offset;
  }

  int newOffset = offset + 1;

  int lineNumber = cm.getLogicalPosition().line;
  int maxOffset = document.getLineEndOffset( lineNumber );
  if( newOffset > maxOffset )
  {
    if( lineNumber + 1 >= document.getLineCount() )
    {
      return offset;
    }
    maxOffset = document.getLineEndOffset( lineNumber + 1 );
  }
  for( ; newOffset < maxOffset; newOffset++ )
  {
    if( EditorActionUtil.isWordOrLexemeEnd( editorImpl, newOffset, false ) )
    {
      break;
    }
  }

  return newOffset;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:47,代碼來源:ResourceToManifoldUtil.java


注:本文中的com.intellij.openapi.editor.Document.getLineEndOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。