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


Java DocumentEvent.getOldLength方法代码示例

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


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

示例1: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public final void documentChanged(@NotNull DocumentEvent e) {
  int oldStart = intervalStart();
  int oldEnd = intervalEnd();
  int docLength = myDocument.getTextLength();
  if (!isValid()) {
    LOG.error("Invalid range marker "+ (isGreedyToLeft() ? "[" : "(") + oldStart + ", " + oldEnd + (isGreedyToRight() ? "]" : ")") +
              ". Event = " + e + ". Doc length=" + docLength + "; "+getClass());
    return;
  }
  if (intervalStart() > intervalEnd() || intervalStart() < 0 || intervalEnd() > docLength - e.getNewLength() + e.getOldLength()) {
    LOG.error("RangeMarker" + (isGreedyToLeft() ? "[" : "(") + oldStart + ", " + oldEnd + (isGreedyToRight() ? "]" : ")") +
              " is invalid before update. Event = " + e + ". Doc length=" + docLength + "; "+getClass());
    invalidate(e);
    return;
  }
  changedUpdateImpl(e);
  if (isValid() && (intervalStart() > intervalEnd() || intervalStart() < 0 || intervalEnd() > docLength)) {
    LOG.error("Update failed. Event = " + e + ". " +
              "old doc length=" + docLength + "; real doc length = "+myDocument.getTextLength()+
              "; "+getClass()+"." +
              " After update: '"+this+"'");
    invalidate(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:RangeMarkerImpl.java

示例2: processIfOnePoint

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Nullable
private static ProperTextRange processIfOnePoint(@NotNull DocumentEvent e, int intervalStart, int intervalEnd, boolean greedyRight) {
  int offset = e.getOffset();
  int oldLength = e.getOldLength();
  int oldEnd = offset + oldLength;
  if (offset < intervalStart && intervalStart < oldEnd) {
    return null;
  }

  if (offset == intervalStart && oldLength == 0 && greedyRight) {
    return new ProperTextRange(intervalStart, intervalEnd + e.getNewLength());
  }

  if (intervalStart > oldEnd || intervalStart == oldEnd  && oldLength > 0) {
    return new ProperTextRange(intervalStart + e.getNewLength() - oldLength, intervalEnd + e.getNewLength() - oldLength);
  }

  return new ProperTextRange(intervalStart, intervalEnd);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:RangeMarkerImpl.java

示例3: fixRanges

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@NotNull
private int[] fixRanges(@NotNull DocumentEvent e, int line1, int line2) {
  CharSequence document = myDocument.getCharsSequence();
  int offset = e.getOffset();

  if (e.getOldLength() == 0 && e.getNewLength() != 0) {
    if (StringUtil.endsWithChar(e.getNewFragment(), '\n') && isNewline(offset - 1, document)) {
      return new int[]{line1, line2 - 1};
    }
    if (StringUtil.startsWithChar(e.getNewFragment(), '\n') && isNewline(offset + e.getNewLength(), document)) {
      return new int[]{line1 + 1, line2};
    }
  }
  if (e.getOldLength() != 0 && e.getNewLength() == 0) {
    if (StringUtil.endsWithChar(e.getOldFragment(), '\n') && isNewline(offset - 1, document)) {
      return new int[]{line1, line2 - 1};
    }
    if (StringUtil.startsWithChar(e.getOldFragment(), '\n') && isNewline(offset + e.getNewLength(), document)) {
      return new int[]{line1 + 1, line2};
    }
  }

  return new int[]{line1, line2};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LineStatusTracker.java

示例4: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
  DocumentEx document = getDocument();
  if (document.isInBulkUpdate()) {
    return;
  }

  if (document.getTextLength() > 0) {
    addLineSeparatorPainterIfNeed();
    int startDocLine = document.getLineNumber(event.getOffset());
    int endDocLine = document.getLineNumber(event.getOffset() + event.getNewLength());
    if (event.getOldLength() > event.getNewLength() || startDocLine != endDocLine || StringUtil.indexOf(event.getOldFragment(), '\n') != -1) {
      updateGutterSize(startDocLine, endDocLine);
    }
  }
  else if (event.getOldLength() > 0) {
    documentCleared();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:LanguageConsoleBuilder.java

示例5: onDocumentChanged2

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
protected void onDocumentChanged2(@NotNull DocumentEvent event) {
  if (!myRangeMarker.isValid()) {
    return;
  }
  if (!myDocument1.isWritable()) return;

  CharSequence newText = event.getNewFragment();
  int originalOffset = event.getOffset() + myRangeMarker.getStartOffset();
  int originalEnd = originalOffset + event.getOldLength();
  replaceString(myDocument1, originalOffset, originalEnd, newText);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:DocumentFragmentContent.java

示例6: onCopyChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
protected void onCopyChanged(@NotNull DocumentEvent event, @NotNull Document original) {
  final int originalOffset = event.getOffset() + myRangeMarker.getStartOffset();
  LOG.assertTrue(originalOffset >= 0);
  if (!original.isWritable()) return;
  final String newText = subText(event.getDocument(), event.getOffset(), event.getNewLength());
  final int originalEnd = originalOffset + event.getOldLength();
  replaceString(original, originalOffset, originalEnd, newText);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:FragmentContent.java

示例7: beforeUpdate

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
public void beforeUpdate(@NotNull DocumentEvent e) {
  if (isZeroLatencyTypingEnabled() && myImmediateEditingInProgress && canPaintImmediately(e)) {
    int offset = e.getOffset();
    int length = e.getOldLength();

    myOldArea = lineRectangleBetween(offset, offset + length);

    myOldTailArea = lineRectangleBetween(offset + length, getDocument().getLineEndOffset(getDocument().getLineNumber(offset)));
    if (myOldTailArea.isEmpty()) {
      myOldTailArea.width += EditorUtil.getSpaceWidth(Font.PLAIN, myEditor); // include possible caret
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ImmediatePainter.java

示例8: needToShiftWhiteSpaces

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
private boolean needToShiftWhiteSpaces(final DocumentEvent e) {
  if (!CharArrayUtil.containsOnlyWhiteSpaces(e.getNewFragment()) || CharArrayUtil.containLineBreaks(e.getNewFragment()))
    return e.getOldLength() > 0;
  if (e.getOffset() == 0) return false;
  final char charBefore = myEditor.getDocument().getCharsSequence().charAt(e.getOffset() - 1);
  //final char charAfter = myEditor.getDocument().getCharsSequence().charAt(e.getOffset() + e.getNewLength());
  return Character.isWhitespace(charBefore)/* || !Character.isWhitespace(charAfter)*/;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:CaretImpl.java

示例9: translateOffset

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Nullable
private static Integer translateOffset(int offset, DocumentEvent event) {
  if (event.getOffset() < offset && offset < event.getOffset() + event.getNewLength()) {
    if (event.getOldLength() == 0) {
      return event.getOffset();
    }

    return null;
  }

  return offset <= event.getOffset() ? offset : offset - event.getNewLength() + event.getOldLength();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:OffsetTranslator.java

示例10: applyEvent

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
public FrozenDocument applyEvent(DocumentEvent event, int newStamp) {
  final int offset = event.getOffset();
  final int oldEnd = offset + event.getOldLength();
  final ImmutableText newText = myText.delete(offset, oldEnd).insert(offset, event.getNewFragment());
  final LineSet newLineSet = myLineSet.update(myText, offset, oldEnd, event.getNewFragment(), event.isWholeTextReplaced());
  return new FrozenDocument(newText, newLineSet, newStamp, null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:FrozenDocument.java

示例11: shouldTranslateViaDiff

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
/**
 * Answers if document region identified by the given range marker should be translated via diff algorithm on document change
 * identified by the given event.
 *
 * @param e             event that describes document change
 * @param rangeMarker   target range marker which update strategy should be selected
 * @return              <code>true</code> if target document range referenced by the given range marker should be translated via
 *                      diff algorithm; <code>false</code> otherwise
 */
static boolean shouldTranslateViaDiff(@NotNull DocumentEvent e, @NotNull Segment rangeMarker) {
  if (e.isWholeTextReplaced()) {
    // Perform translation if the whole text is replaced.
    return true;
  }

  if (e.getOffset() >= rangeMarker.getEndOffset() || e.getOffset() + e.getOldLength() <= rangeMarker.getStartOffset()) {
    // Don't perform complex processing if the change doesn't affect target range.
    return false;
  }

  // Perform complex processing only if significant document part is updated.
  return (Math.max(e.getNewLength(), e.getOldLength()) * 1.0) / e.getDocument().getTextLength() >= 0.8;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PersistentRangeMarkerUtil.java

示例12: isRemoveEvent

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
private boolean isRemoveEvent(DocumentEvent documentEvent) {
    return (documentEvent.getOldLength() > 0 && documentEvent.getNewLength() == 0);
}
 
开发者ID:testmycode,项目名称:tmc-intellij,代码行数:4,代码来源:TextInputListener.java

示例13: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
public void documentChanged(DocumentEvent event) {
  if (event.getOldLength() != event.getNewLength()) myPanel.invalidateDiff();
  requestRediff();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:Rediffers.java

示例14: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
  myTextLength += e.getNewLength() - e.getOldLength();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:EmptyEditorHighlighter.java

示例15: applyChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Nullable
static ProperTextRange applyChange(@NotNull DocumentEvent e, int intervalStart, int intervalEnd, boolean isGreedyToLeft, boolean isGreedyToRight) {
  if (intervalStart == intervalEnd) {
    return processIfOnePoint(e, intervalStart, intervalEnd, isGreedyToRight);
  }

  final int offset = e.getOffset();
  final int oldLength = e.getOldLength();
  final int newLength = e.getNewLength();

  // changes after the end.
  if (intervalEnd < offset) {
    return new ProperTextRange(intervalStart, intervalEnd);
  }
  if (!isGreedyToRight && intervalEnd == offset) {
    // handle replaceString that was minimized and resulted in insertString at the range end
    if (e instanceof DocumentEventImpl && oldLength == 0 && ((DocumentEventImpl)e).getInitialStartOffset() < offset) {
      return new ProperTextRange(intervalStart, intervalEnd + newLength);
    }
    return new ProperTextRange(intervalStart, intervalEnd);
  }

  // changes before start
  if (intervalStart > offset + oldLength) {
    return new ProperTextRange(intervalStart + newLength - oldLength, intervalEnd + newLength - oldLength);
  }
  if (!isGreedyToLeft && intervalStart == offset + oldLength) {
    // handle replaceString that was minimized and resulted in insertString at the range start
    if (e instanceof DocumentEventImpl && oldLength == 0 && ((DocumentEventImpl)e).getInitialStartOffset() + ((DocumentEventImpl)e).getInitialOldLength() > offset) {
      return new ProperTextRange(intervalStart - oldLength, intervalEnd + newLength - oldLength);
    }
    return new ProperTextRange(intervalStart + newLength - oldLength, intervalEnd + newLength - oldLength);
  }

  // Changes inside marker's area. Expand/collapse.
  if (intervalStart <= offset && intervalEnd >= offset + oldLength) {
    return new ProperTextRange(intervalStart, intervalEnd + newLength - oldLength);
  }

  // At this point we either have (myStart xor myEnd inside changed area) or whole area changed.

  // Replacing prefix or suffix...
  if (intervalStart >= offset && intervalStart <= offset + oldLength && intervalEnd > offset + oldLength) {
    return new ProperTextRange(offset + newLength, intervalEnd + newLength - oldLength);
  }

  if (intervalEnd >= offset && intervalEnd <= offset + oldLength && intervalStart < offset) {
    return new ProperTextRange(intervalStart, offset);
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:RangeMarkerImpl.java


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