mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: remove usages of offsets from LineFragment
they are dangerous, as they may contain trailing '\n' and may not (at the end of file).
This commit is contained in:
@@ -64,9 +64,7 @@ public class LineFragmentImpl implements LineFragment {
|
||||
myInnerFragments = dropWholeChangedFragments(innerFragments, endOffset1 - startOffset1, endOffset2 - startOffset2);
|
||||
|
||||
if (myStartLine1 == myEndLine1 &&
|
||||
myStartLine2 == myEndLine2 &&
|
||||
myStartOffset1 == myEndOffset1 &&
|
||||
myStartOffset2 == myEndOffset2) {
|
||||
myStartLine2 == myEndLine2) {
|
||||
LOG.error("LineFragmentImpl should not be empty: " + toString());
|
||||
}
|
||||
if (myStartLine1 > myEndLine1 ||
|
||||
|
||||
@@ -46,18 +46,6 @@ class ChangedBlock {
|
||||
myLineFragment = lineFragment;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChangedBlock createInserted(int length, int lines) {
|
||||
LineFragmentImpl lineFragment = new LineFragmentImpl(0, 0, 0, lines, 0, 0, 0, length);
|
||||
return new ChangedBlock(0, 0, 0, length, 0, lines, lineFragment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChangedBlock createDeleted(int length, int lines) {
|
||||
LineFragmentImpl lineFragment = new LineFragmentImpl(0, lines, 0, 0, 0, length, 0, 0);
|
||||
return new ChangedBlock(0, length, 0, 0, 0, lines, lineFragment);
|
||||
}
|
||||
|
||||
public int getStartOffset1() {
|
||||
return myStartOffset1;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.diff.util.DiffUtil.getLineCount;
|
||||
import static com.intellij.diff.util.DiffUtil.getLinesContent;
|
||||
|
||||
public class UnifiedDiffViewer extends ListenerDiffViewerBase {
|
||||
public static final Logger LOG = Logger.getInstance(UnifiedDiffViewer.class);
|
||||
@@ -1182,9 +1183,8 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase {
|
||||
|
||||
LineFragment lineFragment = change.getLineFragment();
|
||||
|
||||
int insertedStart = lineFragment.getStartOffset2();
|
||||
int insertedEnd = lineFragment.getEndOffset2();
|
||||
CharSequence insertedText = getContent(mySide).getDocument().getCharsSequence().subSequence(insertedStart, insertedEnd);
|
||||
Document document = getContent(mySide).getDocument();
|
||||
CharSequence insertedText = getLinesContent(document, lineFragment.getStartLine2(), lineFragment.getEndLine2());
|
||||
|
||||
int lineNumber = lineFragment.getStartLine2();
|
||||
|
||||
|
||||
@@ -793,8 +793,8 @@ public class DiffUtil {
|
||||
|
||||
@NotNull
|
||||
public static TextDiffType getLineDiffType(@NotNull LineFragment fragment) {
|
||||
boolean left = fragment.getEndOffset1() != fragment.getStartOffset1() || fragment.getStartLine1() != fragment.getEndLine1();
|
||||
boolean right = fragment.getEndOffset2() != fragment.getStartOffset2() || fragment.getStartLine2() != fragment.getEndLine2();
|
||||
boolean left = fragment.getStartLine1() != fragment.getEndLine1();
|
||||
boolean right = fragment.getStartLine2() != fragment.getEndLine2();
|
||||
return getType(left, right);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user