mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: try mark inserted fragments as ignored
This commit is contained in:
+28
-6
@@ -57,15 +57,24 @@ public class ComparisonUtil {
|
||||
int tooBigChunksCount = 0;
|
||||
|
||||
for (LineFragment fragment : lineFragments) {
|
||||
if (tooBigChunksCount >= 3 || // Do not try to build fine blocks after few fails
|
||||
fragment.getStartLine1() == fragment.getEndLine1() ||
|
||||
fragment.getStartLine2() == fragment.getEndLine2()) {
|
||||
fineFragments.add(new FineLineFragmentImpl(fragment, null));
|
||||
CharSequence subSequence1 = text1.subSequence(fragment.getStartOffset1(), fragment.getEndOffset1());
|
||||
CharSequence subSequence2 = text2.subSequence(fragment.getStartOffset2(), fragment.getEndOffset2());
|
||||
|
||||
if (fragment.getStartLine1() == fragment.getEndLine1() ||
|
||||
fragment.getStartLine2() == fragment.getEndLine2()) { // Do not try to build fine blocks after few fails)
|
||||
if (isEquals(subSequence1, subSequence2, policy)) {
|
||||
fineFragments.add(new FineLineFragmentImpl(fragment, Collections.<DiffFragment>emptyList()));
|
||||
}
|
||||
else {
|
||||
fineFragments.add(new FineLineFragmentImpl(fragment, null));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
CharSequence subSequence1 = text1.subSequence(fragment.getStartOffset1(), fragment.getEndOffset1());
|
||||
CharSequence subSequence2 = text2.subSequence(fragment.getStartOffset2(), fragment.getEndOffset2());
|
||||
if (tooBigChunksCount >= 3) { // Do not try to build fine blocks after few fails)
|
||||
fineFragments.add(new FineLineFragmentImpl(fragment, null));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
List<ByWord.LineBlock> lineBlocks = ByWord.compareAndSplit(subSequence1, subSequence2, policy, indicator);
|
||||
@@ -126,6 +135,19 @@ public class ComparisonUtil {
|
||||
return convertIntoFragments(ByChar.compareTwoStep(text1, text2, indicator));
|
||||
}
|
||||
|
||||
public static boolean isEquals(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ComparisonPolicy policy) {
|
||||
switch (policy) {
|
||||
case DEFAULT:
|
||||
return StringUtil.equals(text1, text2);
|
||||
case TRIM_WHITESPACES:
|
||||
return StringUtil.equalsTrimWhitespaces(text1, text2);
|
||||
case IGNORE_WHITESPACES:
|
||||
return StringUtil.equalsIgnoreWhitespaces(text1, text2);
|
||||
default:
|
||||
throw new IllegalArgumentException(policy.name());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Post process line fragments
|
||||
//
|
||||
|
||||
+1
-2
@@ -8,8 +8,7 @@ import java.util.List;
|
||||
public class FineLineFragmentImpl extends LineFragmentImpl implements FineLineFragment {
|
||||
@Nullable protected final List<DiffFragment> myFragments;
|
||||
|
||||
public FineLineFragmentImpl(@NotNull LineFragment fragment,
|
||||
@Nullable List<DiffFragment> fragments) {
|
||||
public FineLineFragmentImpl(@NotNull LineFragment fragment, @Nullable List<DiffFragment> fragments) {
|
||||
super(fragment);
|
||||
|
||||
myFragments = dropWholeChangedFragments(fragments, myEndOffset1 - myStartOffset1, myEndOffset2 - myStartOffset2);
|
||||
|
||||
+2
-11
@@ -7,9 +7,9 @@ import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.editor.markup.SeparatorPlacement;
|
||||
import com.intellij.openapi.util.diff.comparison.ComparisonPolicy;
|
||||
import com.intellij.openapi.util.diff.comparison.ComparisonUtil;
|
||||
import com.intellij.openapi.util.diff.fragments.MergeLineFragment;
|
||||
import com.intellij.openapi.util.diff.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -188,16 +188,7 @@ class SimpleThreesideDiffChange {
|
||||
CharSequence content1 = getRangeContent(fragment, editors, side1);
|
||||
CharSequence content2 = getRangeContent(fragment, editors, side2);
|
||||
|
||||
switch (policy) {
|
||||
case DEFAULT:
|
||||
return StringUtil.equals(content1, content2);
|
||||
case TRIM_WHITESPACES:
|
||||
return StringUtil.equalsTrimWhitespaces(content1, content2);
|
||||
case IGNORE_WHITESPACES:
|
||||
return StringUtil.equalsIgnoreWhitespaces(content1, content2);
|
||||
default:
|
||||
throw new IllegalArgumentException(policy.name());
|
||||
}
|
||||
return ComparisonUtil.isEquals(content1, content2, policy);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user