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(){
|
||||
Block block = new Block("0\n1\n2\n3\n4\n5\n6", 3, 7);
|
||||
|
||||
@@ -46,8 +46,9 @@ public class Block {
|
||||
|
||||
@NotNull
|
||||
public Block createPreviousBlock(@NotNull String[] prevContent) {
|
||||
int startLine = myStart;
|
||||
int endLine = myEnd;
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
int shift = 0;
|
||||
|
||||
Diff.Change change = Diff.buildChangesSomehow(prevContent, getSource());
|
||||
while (change != null) {
|
||||
@@ -56,31 +57,21 @@ public class Block {
|
||||
int endLine1 = startLine1 + change.deleted;
|
||||
int endLine2 = startLine2 + change.inserted;
|
||||
|
||||
int shiftStart = startLine2 - startLine1;
|
||||
int shiftEnd = endLine2 - endLine1;
|
||||
|
||||
if (startLine2 <= myStart) {
|
||||
startLine = myStart - shiftStart;
|
||||
}
|
||||
|
||||
if (endLine2 <= myStart) {
|
||||
startLine = myStart - shiftEnd;
|
||||
}
|
||||
|
||||
if (startLine2 < myEnd) {
|
||||
endLine = myEnd - shiftEnd;
|
||||
if (Math.max(myStart, startLine2) < Math.min(myEnd, endLine2)) {
|
||||
// ranges intersect
|
||||
if (startLine2 <= myStart) start = startLine1;
|
||||
if (endLine2 > myEnd) end = endLine1;
|
||||
}
|
||||
if (start == -1 && startLine2 > myStart) start = myStart - shift;
|
||||
if (end == -1 && startLine2 >= myEnd) end = myEnd - shift;
|
||||
|
||||
shift += change.inserted - change.deleted;
|
||||
change = change.link;
|
||||
}
|
||||
if (start == -1) start = myStart - shift;
|
||||
if (end == -1) end = myEnd - shift;
|
||||
|
||||
if (endLine > prevContent.length) {
|
||||
endLine = prevContent.length;
|
||||
}
|
||||
if (startLine < 0) startLine = 0;
|
||||
if (endLine < startLine) endLine = startLine;
|
||||
|
||||
return new Block(prevContent, startLine, endLine);
|
||||
return new Block(prevContent, start, end);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user