mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: Show History for Selection - more consistent Block logic
greedy expand range on damage
This commit is contained in:
@@ -182,6 +182,17 @@ public class SelectedBlockHistoryTest extends TestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test15() throws FilesTooBigForDiffException {
|
||||||
|
doTest(
|
||||||
|
new String[]{"1"},
|
||||||
|
new String[]{"0"},
|
||||||
|
new String[]{"3"},
|
||||||
|
|
||||||
|
new String[]{"1", "4"},
|
||||||
|
new String[]{"5", "0"},
|
||||||
|
new String[]{"3"}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public void testContent(){
|
public void testContent(){
|
||||||
Block block = new Block("0\n1\n2\n3\n4\n5\n6", 3, 7);
|
Block block = new Block("0\n1\n2\n3\n4\n5\n6", 3, 7);
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ public class Block {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Block createPreviousBlock(@NotNull String[] prevContent) {
|
public Block createPreviousBlock(@NotNull String[] prevContent) {
|
||||||
int startLine = myStart;
|
int start = -1;
|
||||||
int endLine = myEnd;
|
int end = -1;
|
||||||
|
int shift = 0;
|
||||||
|
|
||||||
Diff.Change change = Diff.buildChangesSomehow(prevContent, getSource());
|
Diff.Change change = Diff.buildChangesSomehow(prevContent, getSource());
|
||||||
while (change != null) {
|
while (change != null) {
|
||||||
@@ -56,31 +57,21 @@ public class Block {
|
|||||||
int endLine1 = startLine1 + change.deleted;
|
int endLine1 = startLine1 + change.deleted;
|
||||||
int endLine2 = startLine2 + change.inserted;
|
int endLine2 = startLine2 + change.inserted;
|
||||||
|
|
||||||
int shiftStart = startLine2 - startLine1;
|
if (Math.max(myStart, startLine2) < Math.min(myEnd, endLine2)) {
|
||||||
int shiftEnd = endLine2 - endLine1;
|
// ranges intersect
|
||||||
|
if (startLine2 <= myStart) start = startLine1;
|
||||||
if (startLine2 <= myStart) {
|
if (endLine2 > myEnd) end = endLine1;
|
||||||
startLine = myStart - shiftStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (endLine2 <= myStart) {
|
|
||||||
startLine = myStart - shiftEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startLine2 < myEnd) {
|
|
||||||
endLine = myEnd - shiftEnd;
|
|
||||||
}
|
}
|
||||||
|
if (start == -1 && startLine2 > myStart) start = myStart - shift;
|
||||||
|
if (end == -1 && startLine2 >= myEnd) end = myEnd - shift;
|
||||||
|
|
||||||
|
shift += change.inserted - change.deleted;
|
||||||
change = change.link;
|
change = change.link;
|
||||||
}
|
}
|
||||||
|
if (start == -1) start = myStart - shift;
|
||||||
|
if (end == -1) end = myEnd - shift;
|
||||||
|
|
||||||
if (endLine > prevContent.length) {
|
return new Block(prevContent, start, end);
|
||||||
endLine = prevContent.length;
|
|
||||||
}
|
|
||||||
if (startLine < 0) startLine = 0;
|
|
||||||
if (endLine < startLine) endLine = startLine;
|
|
||||||
|
|
||||||
return new Block(prevContent, startLine, endLine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user