本文整理汇总了Java中com.intellij.openapi.editor.event.DocumentEvent.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent.getOffset方法的具体用法?Java DocumentEvent.getOffset怎么用?Java DocumentEvent.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.event.DocumentEvent
的用法示例。
在下文中一共展示了DocumentEvent.getOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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};
}
示例3: mergeChangesIfNecessary
import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
private void mergeChangesIfNecessary(DocumentEvent event) {
// There is a possible case that we had more than one scattered change (e.g. (3; 5) and (8; 10)) and current document change affects
// both of them (e.g. remove all symbols from offset (4; 9)). We have two changes then: (3; 4) and (4; 5) and want to merge them
// into a single one.
if (myChanges.size() < 2) {
return;
}
TextChangeImpl next = myChanges.get(myChanges.size() - 1);
for (int i = myChanges.size() - 2; i >= 0; i--) {
TextChangeImpl current = myChanges.get(i);
if (current.getEnd() < event.getOffset()) {
// Assuming that change ranges are always kept at normalized form.
break;
}
if (current.getEnd() == next.getStart()) {
myChanges.set(i, next = new TextChangeImpl(current.getText().toString() + next.getText(), current.getStart(), next.getEnd()));
myChanges.remove(i + 1);
}
else {
next = current;
}
}
}
示例4: documentChanged
import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
synchronized (this) {
final Document document = e.getDocument();
Lexer l = getLexer();
// if the document been changed before "from __future__ import unicode_literals"
// we should update the whole document
if (l instanceof LayeredLexer) {
Lexer delegate = ((LayeredLexer)l).getDelegate();
int offset = e.getOffset();
int lineNumber = document.getLineNumber(offset);
TextRange tr = new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber));
document.putUserData(KEY, document.getText(tr).indexOf(PyNames.UNICODE_LITERALS) == -1);
Boolean hasUnicodeImport = document.getUserData(KEY);
if (delegate instanceof PythonHighlightingLexer &&
(((PythonHighlightingLexer)delegate).getImportOffset() > e.getOffset()
|| hasUnicodeImport != hadUnicodeImport)) {
((PythonHighlightingLexer)delegate).clearState(e.getDocument().getTextLength());
setText(document.getCharsSequence());
}
else super.documentChanged(e);
}
else super.documentChanged(e);
}
}
示例5: documentChanged
import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
if (!myTaskFile.isTrackChanges()) {
return;
}
if (myAnswerPlaceholders.isEmpty()) return;
if (e instanceof DocumentEventImpl) {
DocumentEventImpl event = (DocumentEventImpl)e;
Document document = e.getDocument();
int offset = e.getOffset();
int change = event.getNewLength() - event.getOldLength();
for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
int twStart = answerPlaceholderWrapper.getTwStart();
if (twStart > offset) {
twStart += change;
}
int twEnd = answerPlaceholderWrapper.getTwEnd();
if (twEnd >= offset) {
twEnd += change;
}
AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
int length = twEnd - twStart;
answerPlaceholder.setOffset(twStart);
if (myTrackLength) {
if (answerPlaceholder.getUseLength()) {
answerPlaceholder.setLength(length);
} else {
if (answerPlaceholder.isActive() && myTaskFile.isTrackLengths()) {
answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
}
}
}
}
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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
}
}
}
示例9: 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)*/;
}
示例10: 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();
}
示例11: 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);
}
示例12: 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;
}
示例13: updateChanges
import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Updates current object's state on the basis of the given event assuming that there are no stored change ranges that
* start after offset denoted by the given event.
*
* @param event event for just occurred document change
* @param oldText our main idea is to merge all changes in order to have aggregated change against original document. So, there is
* a possible case that subsequent change affects text inserted by the previous one. We don't want to reflect that
* at aggregated change as it didn't appear in initial document. Hence, we have a mutable symbols buffer that holds
* symbols from initial document affected by the given change
*/
private void updateChanges(DocumentEvent event, StringBuilder oldText) {
int i = findIndex(event.getOffset());
int endOffset = event.getOffset() + event.getNewLength();
TextChangeImpl change = new TextChangeImpl(oldText, event.getOffset(), endOffset);
if (i < 0) {
myChanges.add(change);
}
else {
myChanges.add(i, change);
}
}
示例14: documentChanged
import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
if (!myTaskFile.isTrackChanges()) {
return;
}
if (myAnswerPlaceholders.isEmpty()) return;
if (e instanceof DocumentEventImpl) {
DocumentEventImpl event = (DocumentEventImpl)e;
Document document = e.getDocument();
int offset = e.getOffset();
int change = event.getNewLength() - event.getOldLength();
for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
int twStart = answerPlaceholderWrapper.getTwStart();
if (twStart > offset) {
twStart += change;
}
int twEnd = answerPlaceholderWrapper.getTwEnd();
if (twEnd >= offset) {
twEnd += change;
}
AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
int line = document.getLineNumber(twStart);
int start = twStart - document.getLineStartOffset(line);
int length = twEnd - twStart;
answerPlaceholder.setLine(line);
answerPlaceholder.setStart(start);
if (usePossibleAnswerLength) {
answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
}
else if (myTrackLength) {
answerPlaceholder.setLength(length);
}
}
}
}
示例15: EditorChangeAction
import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
public EditorChangeAction(DocumentEvent e) {
this((DocumentEx)e.getDocument(), e.getOffset(), e.getOldFragment(), e.getNewFragment(), e.getOldTimeStamp());
}