mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-26 21:17:20 -08:00
Cherrypick - feature: add buttons to go to prev/next change in text diff view (#616)
Signed-off-by: leo <longshuang@msn.cn>
(cherry picked from commit 134c71064e
)
# Conflicts:
# src/Views/DiffView.axaml
# src/Views/TextDiffView.axaml.cs
This commit is contained in:
parent
96a9019487
commit
1a99ce54d3
1 changed files with 102 additions and 0 deletions
|
@ -647,6 +647,108 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
public void GotoPrevChange()
|
||||
{
|
||||
var view = TextArea.TextView;
|
||||
var lines = GetLines();
|
||||
var firstLineIdx = lines.Count;
|
||||
foreach (var line in view.VisualLines)
|
||||
{
|
||||
if (line.IsDisposed || line.FirstDocumentLine == null || line.FirstDocumentLine.IsDeleted)
|
||||
continue;
|
||||
|
||||
var index = line.FirstDocumentLine.LineNumber - 1;
|
||||
if (index >= lines.Count)
|
||||
continue;
|
||||
|
||||
if (firstLineIdx > index)
|
||||
firstLineIdx = index;
|
||||
}
|
||||
|
||||
var firstLineType = lines[firstLineIdx].Type;
|
||||
var isChangeFirstLine = firstLineType != Models.TextDiffLineType.Normal && firstLineType != Models.TextDiffLineType.Indicator;
|
||||
if (isChangeFirstLine)
|
||||
{
|
||||
for (var i = firstLineIdx - 1; i >= 0; i--)
|
||||
{
|
||||
var prevType = lines[i].Type;
|
||||
if (prevType == Models.TextDiffLineType.Normal || prevType == Models.TextDiffLineType.Indicator)
|
||||
{
|
||||
ScrollToLine(i + 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var prevChangeEnd = -1;
|
||||
for (var i = firstLineIdx - 1; i >= 0; i--)
|
||||
{
|
||||
var prevType = lines[i].Type;
|
||||
if (prevType == Models.TextDiffLineType.None ||
|
||||
prevType == Models.TextDiffLineType.Added ||
|
||||
prevType == Models.TextDiffLineType.Deleted)
|
||||
{
|
||||
prevChangeEnd = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (prevChangeEnd <= 0)
|
||||
return;
|
||||
|
||||
for (var i = prevChangeEnd - 1; i >= 0; i--)
|
||||
{
|
||||
var prevType = lines[i].Type;
|
||||
if (prevType == Models.TextDiffLineType.Normal || prevType == Models.TextDiffLineType.Indicator)
|
||||
{
|
||||
ScrollToLine(i + 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GotoNextChange()
|
||||
{
|
||||
var view = TextArea.TextView;
|
||||
var lines = GetLines();
|
||||
var lastLineIdx = -1;
|
||||
foreach (var line in view.VisualLines)
|
||||
{
|
||||
if (line.IsDisposed || line.FirstDocumentLine == null || line.FirstDocumentLine.IsDeleted)
|
||||
continue;
|
||||
|
||||
var index = line.FirstDocumentLine.LineNumber - 1;
|
||||
if (index >= lines.Count)
|
||||
continue;
|
||||
|
||||
if (lastLineIdx < index)
|
||||
lastLineIdx = index;
|
||||
}
|
||||
|
||||
var lastLineType = lines[lastLineIdx].Type;
|
||||
var findNormalLine = lastLineType == Models.TextDiffLineType.Normal || lastLineType == Models.TextDiffLineType.Indicator;
|
||||
for (var idx = lastLineIdx + 1; idx < lines.Count; idx++)
|
||||
{
|
||||
var nextType = lines[idx].Type;
|
||||
if (nextType == Models.TextDiffLineType.None ||
|
||||
nextType == Models.TextDiffLineType.Added ||
|
||||
nextType == Models.TextDiffLineType.Deleted)
|
||||
{
|
||||
if (findNormalLine)
|
||||
{
|
||||
ScrollToLine(idx + 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!findNormalLine)
|
||||
{
|
||||
findNormalLine = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
|
|
Loading…
Reference in a new issue