mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lst: move few methods inside LST
* do not treat line as modified if it lies right next to the modified one * avoid unnecessary List<Range> copying
This commit is contained in:
committed by
Aleksey Pivovarov
parent
e65de82d70
commit
ca4eafbe55
@@ -56,6 +56,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.diff.util.DiffUtil.getLineCount;
|
||||
import static com.intellij.openapi.localVcs.UpToDateLineNumberProvider.ABSENT_LINE_NUMBER;
|
||||
|
||||
/**
|
||||
* @author irengrig
|
||||
@@ -895,6 +896,58 @@ public class LineStatusTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLineModified(int line) {
|
||||
return isRangeModified(line, line + 1);
|
||||
}
|
||||
|
||||
public boolean isRangeModified(int line1, int line2) {
|
||||
synchronized (LOCK) {
|
||||
if (!isValid()) return false;
|
||||
if (line1 == line2) return false;
|
||||
assert line1 < line2;
|
||||
|
||||
for (Range range : myRanges) {
|
||||
if (range.getLine1() >= line2) return false;
|
||||
if (range.getLine2() > line1) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int transferLineToFromVcs(int line, boolean approximate) {
|
||||
return transferLine(line, approximate, true);
|
||||
}
|
||||
|
||||
public int transferLineToVcs(int line, boolean approximate) {
|
||||
return transferLine(line, approximate, false);
|
||||
}
|
||||
|
||||
private int transferLine(int line, boolean approximate, boolean fromVcs) {
|
||||
synchronized (LOCK) {
|
||||
if (!isValid()) return approximate ? line : ABSENT_LINE_NUMBER;
|
||||
|
||||
int result = line;
|
||||
|
||||
for (Range range : myRanges) {
|
||||
int startLine1 = fromVcs ? range.getVcsLine1() : range.getLine1();
|
||||
int endLine1 = fromVcs ? range.getVcsLine2() : range.getLine2();
|
||||
int startLine2 = fromVcs ? range.getLine1() : range.getVcsLine1();
|
||||
int endLine2 = fromVcs ? range.getLine2() : range.getVcsLine2();
|
||||
|
||||
if (startLine1 <= line && endLine1 > line) {
|
||||
return approximate ? startLine2 : ABSENT_LINE_NUMBER;
|
||||
}
|
||||
|
||||
if (endLine1 > line) return result;
|
||||
|
||||
int length1 = endLine1 - startLine1;
|
||||
int length2 = endLine2 - startLine2;
|
||||
result += length2 - length1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RevisionPack {
|
||||
private final long myNumber;
|
||||
private final VcsRevisionNumber myRevision;
|
||||
|
||||
+6
-59
@@ -19,46 +19,26 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.ex.LineStatusTracker;
|
||||
import com.intellij.openapi.vcs.ex.Range;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* author: lesya
|
||||
*/
|
||||
public class UpToDateLineNumberProviderImpl implements UpToDateLineNumberProvider {
|
||||
private final Document myDocument;
|
||||
private final Project myProject;
|
||||
private final LineStatusTrackerManagerI myLineStatusTrackerManagerI;
|
||||
|
||||
public UpToDateLineNumberProviderImpl(Document document, Project project) {
|
||||
myDocument = document;
|
||||
myProject = project;
|
||||
myLineStatusTrackerManagerI = LineStatusTrackerManager.getInstance(myProject);
|
||||
myLineStatusTrackerManagerI = LineStatusTrackerManager.getInstance(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRangeChanged(final int start, final int end) {
|
||||
LineStatusTracker tracker = myLineStatusTrackerManagerI.getLineStatusTracker(myDocument);
|
||||
if (tracker == null) {
|
||||
return false;
|
||||
}
|
||||
List<Range> ranges = tracker.getRanges();
|
||||
if (ranges == null) {
|
||||
return false;
|
||||
}
|
||||
for (Range range : ranges) {
|
||||
if (lineInRange(range, start) || lineInRange(range, end)) {
|
||||
return true;
|
||||
}
|
||||
if (range.getLine1() > start) {
|
||||
return range.getLine1() < end;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean lineInRange(final Range range, final int currentNumber) {
|
||||
return range.getLine1() <= currentNumber && range.getLine2() >= currentNumber;
|
||||
return tracker.isRangeModified(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,48 +47,15 @@ public class UpToDateLineNumberProviderImpl implements UpToDateLineNumberProvide
|
||||
if (tracker == null) {
|
||||
return false;
|
||||
}
|
||||
List<Range> ranges = tracker.getRanges();
|
||||
if (ranges == null) {
|
||||
return false;
|
||||
}
|
||||
for (Range range : ranges) {
|
||||
if (range.getLine1() <= currentNumber && range.getLine2() >= currentNumber) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return tracker.isLineModified(currentNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLineNumber(int currentNumber) {
|
||||
LineStatusTracker tracker = myLineStatusTrackerManagerI.getLineStatusTracker(myDocument);
|
||||
if (tracker == null) {
|
||||
return currentNumber;
|
||||
}
|
||||
List<Range> ranges = tracker.getRanges();
|
||||
if (ranges == null) {
|
||||
return currentNumber;
|
||||
}
|
||||
int result = currentNumber;
|
||||
|
||||
for (final Range range : ranges) {
|
||||
int startLine = range.getLine1();
|
||||
int endLine = range.getLine2();
|
||||
|
||||
if ((startLine <= currentNumber) && (endLine > currentNumber)) {
|
||||
return ABSENT_LINE_NUMBER;
|
||||
}
|
||||
|
||||
if (endLine > currentNumber) return result;
|
||||
|
||||
int currentRangeLength = endLine - startLine;
|
||||
int vcsRangeLength = range.getVcsLine2() - range.getVcsLine1();
|
||||
|
||||
result += vcsRangeLength - currentRangeLength;
|
||||
}
|
||||
return result;
|
||||
|
||||
return tracker.transferLineToVcs(currentNumber, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user