mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: fix "Ignore Imports and Formatting" mode with partial changes
* convert ignored ranges to relative offsets
This commit is contained in:
+16
-28
@@ -16,7 +16,6 @@
|
||||
package com.intellij.diff.tools.util.text;
|
||||
|
||||
import com.intellij.diff.comparison.ComparisonManagerImpl;
|
||||
import com.intellij.diff.comparison.TrimUtil;
|
||||
import com.intellij.diff.contents.DiffContent;
|
||||
import com.intellij.diff.fragments.LineFragment;
|
||||
import com.intellij.diff.lang.DiffIgnoredRangeProvider;
|
||||
@@ -38,12 +37,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.diff.tools.util.base.HighlightPolicy.*;
|
||||
import static com.intellij.diff.tools.util.base.IgnorePolicy.*;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public class SmartTextDiffProvider extends TwosideTextDiffProviderBase implements TwosideTextDiffProvider {
|
||||
private static final IgnorePolicy[] IGNORE_POLICIES = {DEFAULT, TRIM_WHITESPACES, IGNORE_WHITESPACES, IGNORE_WHITESPACES_CHUNKS, FORMATTING};
|
||||
@@ -144,38 +141,26 @@ public class SmartTextDiffProvider extends TwosideTextDiffProviderBase implement
|
||||
List<TextRange> ranges1 = myProvider.getIgnoredRanges(myProject, text1, myContent1);
|
||||
List<TextRange> ranges2 = myProvider.getIgnoredRanges(myProject, text2, myContent2);
|
||||
|
||||
BitSet ignored1 = ComparisonManagerImpl.collectIgnoredRanges(ranges1);
|
||||
BitSet ignored2 = ComparisonManagerImpl.collectIgnoredRanges(ranges2);
|
||||
|
||||
List<List<LineFragment>> result = new ArrayList<>();
|
||||
for (Range range : linesRanges) {
|
||||
TextRange offsets1 = DiffUtil.getLinesRange(lineOffsets1, range.start1, range.end1, true);
|
||||
TextRange offsets2 = DiffUtil.getLinesRange(lineOffsets2, range.start2, range.end2, true);
|
||||
|
||||
if (range.start1 == range.end1 || range.start2 == range.end2) {
|
||||
boolean isEquals = TrimUtil.trimExpandText(text1, text2,
|
||||
offsets1.getStartOffset(), offsets2.getStartOffset(),
|
||||
offsets1.getEndOffset(), offsets2.getEndOffset(),
|
||||
ignored1, ignored2).isEmpty();
|
||||
result.add(singletonList(SimpleTextDiffProvider.createSimpleFragment(range, lineOffsets1, lineOffsets2, isEquals)));
|
||||
}
|
||||
else {
|
||||
CharSequence subText1 = offsets1.subSequence(text1);
|
||||
CharSequence subText2 = offsets2.subSequence(text2);
|
||||
CharSequence subText1 = offsets1.subSequence(text1);
|
||||
CharSequence subText2 = offsets2.subSequence(text2);
|
||||
|
||||
List<TextRange> subRanges1 = getSubRanges(ranges1, offsets1);
|
||||
List<TextRange> subRanges2 = getSubRanges(ranges2, offsets2);
|
||||
List<TextRange> subRanges1 = getSubRanges(ranges1, offsets1);
|
||||
List<TextRange> subRanges2 = getSubRanges(ranges2, offsets2);
|
||||
|
||||
ComparisonManagerImpl comparisonManager = ComparisonManagerImpl.getInstanceImpl();
|
||||
List<LineFragment> fragments = comparisonManager.compareLinesWithIgnoredRanges(subText1, subText2, subRanges1, subRanges2,
|
||||
innerFragments, indicator);
|
||||
ComparisonManagerImpl comparisonManager = ComparisonManagerImpl.getInstanceImpl();
|
||||
List<LineFragment> fragments = comparisonManager.compareLinesWithIgnoredRanges(subText1, subText2, subRanges1, subRanges2,
|
||||
innerFragments, indicator);
|
||||
|
||||
int startOffset1 = offsets1.getStartOffset();
|
||||
int startOffset2 = offsets2.getStartOffset();
|
||||
result.add(ContainerUtil.map(fragments, fragment -> {
|
||||
return SimpleTextDiffProvider.transferFragment(fragment, range.start1, range.start2, startOffset1, startOffset2);
|
||||
}));
|
||||
}
|
||||
int startOffset1 = offsets1.getStartOffset();
|
||||
int startOffset2 = offsets2.getStartOffset();
|
||||
result.add(ContainerUtil.map(fragments, fragment -> {
|
||||
return SimpleTextDiffProvider.transferFragment(fragment, range.start1, range.start2, startOffset1, startOffset2);
|
||||
}));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -185,7 +170,10 @@ public class SmartTextDiffProvider extends TwosideTextDiffProviderBase implement
|
||||
List<TextRange> result = new ArrayList<>();
|
||||
for (TextRange range : ignoredRanges) {
|
||||
TextRange intersection = range.intersection(offsets);
|
||||
if (intersection != null) result.add(intersection);
|
||||
if (intersection != null) {
|
||||
result.add(new TextRange(intersection.getStartOffset() - offsets.getStartOffset(),
|
||||
intersection.getEndOffset() - offsets.getStartOffset()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -157,6 +157,16 @@ class IgnoreComparisonUtilTest : DiffTestCase() {
|
||||
" +++", "",
|
||||
"----", "")
|
||||
.run()
|
||||
|
||||
Test("A_B_C_", "",
|
||||
" +++++", "",
|
||||
"-- ", "")
|
||||
.run()
|
||||
|
||||
Test("A_B_C_", "",
|
||||
"++++ +", "",
|
||||
" --", "")
|
||||
.run()
|
||||
}
|
||||
|
||||
fun testLines() {
|
||||
|
||||
Reference in New Issue
Block a user