本文整理汇总了Java中com.intellij.openapi.editor.impl.TextChangeImpl类的典型用法代码示例。如果您正苦于以下问题:Java TextChangeImpl类的具体用法?Java TextChangeImpl怎么用?Java TextChangeImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextChangeImpl类属于com.intellij.openapi.editor.impl包,在下文中一共展示了TextChangeImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchesOldSoftWrap
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
boolean matchesOldSoftWrap(SoftWrap newSoftWrap, int lengthDiff) {
return Collections.binarySearch(myAffectedByUpdateSoftWraps, new SoftWrapImpl(new TextChangeImpl(newSoftWrap.getText(),
newSoftWrap.getStart() - lengthDiff,
newSoftWrap.getEnd() - lengthDiff),
newSoftWrap.getIndentInColumns(),
newSoftWrap.getIndentInPixels()),
new Comparator<SoftWrapImpl>() {
@Override
public int compare(SoftWrapImpl o1, SoftWrapImpl o2) {
int offsetDiff = o1.getStart() - o2.getStart();
if (offsetDiff != 0) {
return offsetDiff;
}
int textDiff = o1.getText().toString().compareTo(o2.getText().toString());
if (textDiff != 0) {
return textDiff;
}
int colIndentDiff = o1.getIndentInColumns() - o2.getIndentInColumns();
if (colIndentDiff != 0) {
return colIndentDiff;
}
return o1.getIndentInPixels() - o2.getIndentInPixels();
}
}) >= 0;
}
示例2: doTest
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
private void doTest(String initial, String expected, TextChangeImpl ... changes) {
if (myConfig.inplace()) {
int diff = 0;
for (TextChangeImpl change : changes) {
diff += change.getDiff();
}
int outputUsefulLength = initial.length() + diff;
int dataLength = myConfig.dataArrayLength();
if (dataLength < 0) {
dataLength = Math.max(outputUsefulLength, initial.length());
}
char[] data = new char[dataLength];
System.arraycopy(initial.toCharArray(), 0, data, 0, initial.length());
myMerger.mergeInPlace(data, initial.length(), Arrays.asList(changes));
assertEquals(expected, new String(data, 0, outputUsefulLength));
}
else {
int interestedSymbolsNumber = myConfig.initialTextLength();
if (interestedSymbolsNumber < 0) {
interestedSymbolsNumber = initial.length();
}
CharSequence actual = myMerger.mergeToCharSequence(initial.toCharArray(), interestedSymbolsNumber, Arrays.asList(changes));
assertEquals(expected, actual.toString());
}
}
示例3: 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;
}
}
}
示例4: matchesOldSoftWrap
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
boolean matchesOldSoftWrap(SoftWrap newSoftWrap, int lengthDiff) {
return Collections.binarySearch(myAffectedByUpdateSoftWraps, new SoftWrapImpl(new TextChangeImpl(newSoftWrap.getText(),
newSoftWrap.getStart() - lengthDiff,
newSoftWrap.getEnd() - lengthDiff),
newSoftWrap.getIndentInColumns(),
newSoftWrap.getIndentInPixels()),
(o1, o2) -> {
int offsetDiff = o1.getStart() - o2.getStart();
if (offsetDiff != 0) {
return offsetDiff;
}
int textDiff = o1.getText().toString().compareTo(o2.getText().toString());
if (textDiff != 0) {
return textDiff;
}
int colIndentDiff = o1.getIndentInColumns() - o2.getIndentInColumns();
if (colIndentDiff != 0) {
return colIndentDiff;
}
return o1.getIndentInPixels() - o2.getIndentInPixels();
}) >= 0;
}
示例5: cutMultipleChanges
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
@Test
public void cutMultipleChanges() {
populate(3, 3, "ABC");
populate(8, 8, "DEF");
populate(5, 9, "");
checkResult(new TextChangeImpl("34", 3, 7));
}
示例6: mergeMultipleChangesInOne
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
@Test
public void mergeMultipleChangesInOne() {
populate(3, 3, "AB");
populate(9, 9, "CD");
populate(5, 9, "EFGH");
checkResult(new TextChangeImpl("3456", 3, 11));
}
示例7: mergeChangesSequence
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
@Test
public void mergeChangesSequence() {
populate(1, 1, "AB");
populate(3, 3, "CD");
populate(5, 5, "EFGH");
checkResult(new TextChangeImpl("", 1, 9));
}
示例8: onSoftWrapEnd
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
public void onSoftWrapEnd() {
myStorage.storeOrReplace(
new SoftWrapImpl(
new TextChangeImpl('\n' + mySoftWrapBuffer.toString(), softWrapStartOffset),
mySoftWrapBuffer.length() + 1/* for 'after soft wrap' drawing */,
(mySoftWrapBuffer.length() * SPACE_SIZE) + SOFT_WRAP_DRAWING_WIDTH
));
mySoftWrapBuffer.setLength(0);
insideSoftWrap = false;
x += SOFT_WRAP_DRAWING_WIDTH;
}
示例9: propertiesExposing
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
@Test
public void propertiesExposing() {
int start = 1;
int end = 10;
String text = "test";
TextChange textChange = new TextChangeImpl(text, start, end);
assertTrue(StringUtil.equals(text, textChange.getText()));
assertArrayEquals(text.toCharArray(), textChange.getChars());
assertEquals(start, textChange.getStart());
assertEquals(end, textChange.getEnd());
}
示例10: 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);
}
}
示例11: updateChanges
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的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);
}
}
示例12: 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;
}
示例13: onSoftWrapEnd
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
public void onSoftWrapEnd() {
myStorage.storeOrReplace(
new SoftWrapImpl(
new TextChangeImpl('\n' + mySoftWrapBuffer.toString(), softWrapStartOffset),
mySoftWrapBuffer.length() + 1/* for 'after soft wrap' drawing */,
(mySoftWrapBuffer.length() * SPACE_SIZE) + SOFT_WRAP_DRAWING_WIDTH
),
false
);
mySoftWrapBuffer.setLength(0);
insideSoftWrap = false;
x += SOFT_WRAP_DRAWING_WIDTH;
}
示例14: SoftWrapImpl
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
public SoftWrapImpl(@NotNull TextChangeImpl change, int indentInColumns, int indentInPixels) {
myChange = change;
myIndentInColumns = indentInColumns;
myIndentInPixels = indentInPixels;
}
示例15: getChange
import com.intellij.openapi.editor.impl.TextChangeImpl; //导入依赖的package包/类
public TextChangeImpl getChange() {
return myChange;
}