Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 81c53cc

Browse files
committed
Enable matching when target line has changed
When target line has changed, search for alternative exact line matches above and use matched line as offset.
1 parent 6a3ecae commit 81c53cc

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/GitHub.App/Services/NavigationService.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class NavigationService : INavigationService
1414
{
1515
readonly IServiceProvider serviceProvider;
1616

17+
// If the target line doesn't have a unique match, search this number of lines above looking for a match.
18+
public const int MatchLinesAboveTarget = 4;
19+
1720
[ImportingConstructor]
1821
public NavigationService([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
1922
{
@@ -56,8 +59,39 @@ public IVsTextView FindActiveView()
5659

5760
public int FindMatchingLine(IList<string> fromLines, IList<string> toLines, int line)
5861
{
59-
int matchedLines;
60-
return FindNearestMatchingLine(fromLines, toLines, line, out matchedLines);
62+
var matchingLine = -1;
63+
var minMatchedLines = -1;
64+
for (var offset = 0; offset <= MatchLinesAboveTarget; offset++)
65+
{
66+
var targetLine = line - offset;
67+
if (targetLine < 0)
68+
{
69+
break;
70+
}
71+
72+
int matchedLines;
73+
var nearestLine = FindNearestMatchingLine(fromLines, toLines, targetLine, out matchedLines);
74+
if (nearestLine != -1)
75+
{
76+
if (matchingLine == -1 || minMatchedLines >= matchedLines)
77+
{
78+
matchingLine = nearestLine + offset;
79+
minMatchedLines = matchedLines;
80+
}
81+
82+
if (minMatchedLines == 1)
83+
{
84+
break; // We've found a unique matching line!
85+
}
86+
}
87+
}
88+
89+
if (matchingLine >= toLines.Count)
90+
{
91+
matchingLine = toLines.Count - 1;
92+
}
93+
94+
return matchingLine;
6195
}
6296

6397
public int FindNearestMatchingLine(IList<string> fromLines, IList<string> toLines, int line, out int matchedLines)

0 commit comments

Comments
 (0)