mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-19061 Integrate the Rearranger-plugin into core-IDEA
Refining API for range markers to survive rearrangement
This commit is contained in:
@@ -37,18 +37,18 @@ public interface DocumentEx extends Document {
|
||||
void replaceText(@NotNull CharSequence chars, long newModificationStamp);
|
||||
|
||||
/**
|
||||
* Replaces <code>[dstStart; dstEnd)</code> range by the text from the <code>[src start; src end)</code> range.
|
||||
* Moves text from the <code>[src start; src end)</code> range to the <code>[dstStart; dstEnd)</code> range.
|
||||
* <p/>
|
||||
* The benefit to use this method over usual {@link #replaceString(int, int, CharSequence)} is that
|
||||
* {@link #createRangeMarker(int, int, boolean) range markers} from the <code>[srcStart; srcEnd)</code> range have
|
||||
* The benefit to use this method over usual {@link #deleteString(int, int)} and {@link #replaceString(int, int, CharSequence)}
|
||||
* is that {@link #createRangeMarker(int, int, boolean) range markers} from the <code>[srcStart; srcEnd)</code> range have
|
||||
* a chance to be preserved.
|
||||
*
|
||||
* @param srcStart start offset of the text to copy (inclusive)
|
||||
* @param srcEnd end offset of the text to copy (exclusive)
|
||||
* @param srcStart start offset of the text to move (inclusive)
|
||||
* @param srcEnd end offset of the text to move (exclusive)
|
||||
* @param dstStart start offset of the range which text should be replaced (inclusive)
|
||||
* @param dstEnd end offset of the range which text should be replaced (exclusive)
|
||||
*/
|
||||
void copyText(int srcStart, int srcEnd, int dstStart, int dstEnd);
|
||||
void moveText(int srcStart, int srcEnd, int dstStart, int dstEnd);
|
||||
|
||||
int getListenersCount();
|
||||
|
||||
|
||||
@@ -368,8 +368,49 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyText(int srcStart, int srcEnd, int dstStart, int dstEnd) {
|
||||
replaceString(dstStart, dstEnd, getCharsSequence().subSequence(srcStart, srcEnd));
|
||||
public void moveText(int srcStart, int srcEnd, int dstStart, int dstEnd) {
|
||||
assertBounds(srcStart, srcEnd);
|
||||
assertBounds(dstStart, dstEnd);
|
||||
|
||||
if (srcStart == dstStart && srcEnd == dstEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
CharSequence replacement = getCharsSequence().subSequence(srcStart, srcEnd);
|
||||
|
||||
// Handle a situation when target ranges don't cross.
|
||||
if (srcEnd <= dstStart || srcStart >= dstEnd) {
|
||||
replaceString(dstStart, dstEnd, replacement);
|
||||
int shift = 0;
|
||||
if (dstStart < srcStart) {
|
||||
shift = (dstEnd - dstStart) - (srcEnd - srcStart);
|
||||
}
|
||||
deleteString(srcStart + shift, srcEnd + shift);
|
||||
return;
|
||||
}
|
||||
|
||||
// _____|__________|__________|________|_____
|
||||
// DstStart SrcStart DstEnd SrcEnd
|
||||
if (dstStart <= srcStart && dstEnd <= srcEnd) {
|
||||
if (dstEnd < srcEnd) {
|
||||
deleteString(dstEnd, srcEnd);
|
||||
}
|
||||
replaceString(dstStart, dstEnd, replacement);
|
||||
}
|
||||
// _____|__________|__________|________|_____
|
||||
// DstStart SrcStart SrcEnd DstEnd
|
||||
// OR
|
||||
// _____|__________|__________|________|_____
|
||||
// SrcStart DstStart DstEnd SrcEnd
|
||||
else if ((dstStart <= srcStart && dstEnd > srcEnd) || (dstStart > srcStart && dstEnd <= srcEnd)) {
|
||||
replaceString(dstStart, dstEnd, replacement);
|
||||
}
|
||||
// _____|__________|__________|________|_____
|
||||
// SrcStart DstStart SrcEnd DstEnd
|
||||
else {
|
||||
replaceString(dstStart, dstEnd, replacement);
|
||||
deleteString(srcStart, dstStart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -391,8 +391,9 @@ public class DocumentWindowImpl extends UserDataHolderBase implements Disposable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyText(int srcStart, int srcEnd, int dstStart, int dstEnd) {
|
||||
replaceString(dstStart, dstEnd, getCharsSequence().subSequence(srcStart, srcEnd));
|
||||
public void moveText(int srcStart, int srcEnd, int dstStart, int dstEnd) {
|
||||
// TODO den implement
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -127,8 +127,9 @@ public class MockDocument implements DocumentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyText(int srcStart, int srcEnd, int dstStart, int dstEnd) {
|
||||
replaceString(dstStart, dstEnd, getCharsSequence().subSequence(srcStart, srcEnd));
|
||||
public void moveText(int srcStart, int srcEnd, int dstStart, int dstEnd) {
|
||||
// TODO den implement
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user