当前位置: 首页>>代码示例>>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;未经允许,请勿转载。