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


Java DocumentUtil.getFirstNonSpaceCharOffset方法代码示例

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


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

示例1: saveIndent

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private static void saveIndent(AnswerPlaceholder placeholder, CCState state, boolean visible) {
  Document document = state.getEditor().getDocument();
  int offset = placeholder.getOffset();
  int lineNumber = document.getLineNumber(offset);
  int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
  int newOffset = offset;
  int endOffset = offset + placeholder.getRealLength();
  if (!visible && nonSpaceCharOffset == offset) {
    newOffset = document.getLineStartOffset(lineNumber);
  }
  if (visible) {
    newOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, offset, endOffset);
  }
  placeholder.setOffset(newOffset);
  int delta = offset - newOffset;
  placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
  String oldTaskText = placeholder.getTaskText();
  if (delta >= 0) {
    placeholder.setTaskText(StringUtil.repeat(" ", delta) + oldTaskText);
  }
  else {
    String newTaskText = oldTaskText.substring(Math.abs(delta));
    placeholder.setTaskText(newTaskText);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:26,代码来源:CCChangePlaceholderVisibility.java

示例2: createLineMarker

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@NotNull
public static List<RangeHighlighter> createLineMarker(@NotNull final Editor editor, int line, @NotNull final SeparatorPlacement placement,
                                                      @Nullable TextDiffType type, @NotNull LineSeparatorRenderer renderer, boolean applied) {
  // We won't use addLineHighlighter as it will fail to add marker into empty document.
  //RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null);

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line);
  RangeHighlighter highlighter = editor.getMarkupModel()
    .addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE);

  highlighter.setLineSeparatorPlacement(placement);
  highlighter.setLineSeparatorRenderer(renderer);

  if (type == null || applied) return Collections.singletonList(highlighter);

  TextAttributes stripeAttributes = getStripeTextAttributes(type, editor);
  RangeHighlighter stripeHighlighter = editor.getMarkupModel()
    .addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE);

  return ContainerUtil.list(highlighter, stripeHighlighter);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DiffDrawUtil.java

示例3: visit

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
/**
 * Read action will be taken automatically
 */
public static <RESULT> RESULT visit(@NotNull XSourcePosition position, @NotNull Project project, @NotNull Visitor<RESULT> visitor, RESULT defaultResult) {
  AccessToken token = ReadAction.start();
  try {
    Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
    PsiFile file = document == null || document.getTextLength() == 0 ? null : PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null) {
      return defaultResult;
    }

    int positionOffset;
    int column = position instanceof SourceInfo ? Math.max(((SourceInfo)position).getColumn(), 0) : 0;
    try {
      positionOffset = column == 0 ? DocumentUtil.getFirstNonSpaceCharOffset(document, position.getLine()) : document.getLineStartOffset(position.getLine()) + column;
    }
    catch (IndexOutOfBoundsException ignored) {
      return defaultResult;
    }

    PsiElement element = file.findElementAt(positionOffset);
    return element == null ? defaultResult : visitor.visit(element, positionOffset, document);
  }
  finally {
    token.finish();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PsiVisitors.java

示例4: done

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@Nonnull
public List<RangeHighlighter> done() {
  // We won't use addLineHighlighter as it will fail to add marker into empty document.
  //RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null);

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line);
  RangeHighlighter highlighter = editor.getMarkupModel()
          .addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE);

  highlighter.setLineSeparatorPlacement(placement);
  highlighter.setLineSeparatorRenderer(renderer);
  highlighter.setLineMarkerRenderer(gutterRenderer);

  if (type == null || resolved) return Collections.singletonList(highlighter);

  TextAttributes stripeAttributes = getStripeTextAttributes(type, editor);
  RangeHighlighter stripeHighlighter = editor.getMarkupModel()
          .addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE);

  return ContainerUtil.list(highlighter, stripeHighlighter);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:DiffDrawUtil.java

示例5: getPlaceholderOffsets

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
public static Pair<Integer, Integer> getPlaceholderOffsets(@NotNull final AnswerPlaceholder answerPlaceholder,
                                                           @NotNull final Document document) {
  int startOffset = answerPlaceholder.getOffset();
  int delta = 0;
  final int length = answerPlaceholder.getRealLength();
  int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, startOffset, startOffset + length);
  if (nonSpaceCharOffset != startOffset) {
    delta = startOffset - nonSpaceCharOffset;
    startOffset = nonSpaceCharOffset;
  }
  final int endOffset = startOffset + length + delta;
  return Pair.create(startOffset, endOffset);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:14,代码来源:StudyUtils.java

示例6: addLineHighlighter

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@Override
@NotNull
public RangeHighlighter addLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) {
  if (isNotValidLine(lineNumber)) {
    throw new IndexOutOfBoundsException("lineNumber:" + lineNumber + ". Must be in [0, " + (getDocument().getLineCount() - 1) + "]");
  }

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber);
  return addRangeHighlighter(offset, offset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:MarkupModelImpl.java

示例7: addPersistentLineHighlighter

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@Override
@Nullable
public RangeHighlighterEx addPersistentLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) {
  if (isNotValidLine(lineNumber)) {
    return null;
  }

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber);
  return addRangeHighlighter(PersistentRangeHighlighterImpl.create(this, offset, layer, HighlighterTargetArea.LINES_IN_RANGE, textAttributes, false), null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:MarkupModelImpl.java

示例8: changeIndent

import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private static void changeIndent(@NotNull ChangeIndentContext context, int newIndent) {
  int caretOffset = context.editor.getCaretModel().getOffset();
  String newIndentString = new IndentInfo(0, newIndent, 0).generateNewWhiteSpace(context.getIndentOptions());
  int start = context.document.getLineStartOffset(context.targetLine);
  int end = DocumentUtil.getFirstNonSpaceCharOffset(context.document, context.targetLine);
  context.editor.getDocument().replaceString(start, end, newIndentString);
  if (caretOffset > start && caretOffset < end) {
    context.editor.getCaretModel().moveToOffset(start + newIndentString.length());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:PyEmacsHandler.java


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