本文整理汇总了Java中com.intellij.openapi.editor.impl.TextChangeImpl.getStart方法的典型用法代码示例。如果您正苦于以下问题:Java TextChangeImpl.getStart方法的具体用法?Java TextChangeImpl.getStart怎么用?Java TextChangeImpl.getStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.impl.TextChangeImpl
的用法示例。
在下文中一共展示了TextChangeImpl.getStart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeChangesIfNecessary
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入方法依赖的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;
}
}
}
示例2: advance
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入方法依赖的package包/类
@Test
public void advance() {
TextChangeImpl base = new TextChangeImpl("xyz", 3, 5);
int[] offsets = {5, 0, -3};
for (int offset : offsets) {
int start = base.getStart();
int end = base.getEnd();
base.advance(offset);
assertEquals(new TextChangeImpl(base.getText(), start + offset, end + offset), base);
}
}
示例3: findIndex
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入方法依赖的package包/类
/**
* Finds index of the {@link #myCollectChanges first stored changed document ranges} which start offset is equal or greater to the
* given one.
*
* @param offset start offset of target document change
* @return non-negative value as an indication that there is not stored changed document range which start offset is equal
* or greater than the given offset; negative value otherwise
*/
private int findIndex(int offset) {
if (myChanges.isEmpty()) {
return -1;
}
// We assume that document is changed sequentially from start to end, hence, it's worth to perform quick offset comparison with
// the last stored change if any
TextChangeImpl change = myChanges.get(myChanges.size() - 1);
if (offset > change.getStart()) {
return -1;
}
int start = 0;
int end = myChanges.size() - 1;
int result = -1;
// We inline binary search here mainly because TextChange class is immutable and we don't want unnecessary expenses on
// new key object construction on every method call.
while (start <= end) {
result = (end + start) >>> 1;
change = myChanges.get(result);
if (change.getStart() < offset) {
start = ++result;
continue;
}
if (change.getStart() > offset) {
end = result - 1;
continue;
}
break;
}
return result;
}