mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
optimize<DiffViewer>: ignore "No new line at end of file" in diff outputs; add IsContent and IsDifference methods for ChangeBlock
This commit is contained in:
parent
06b5709a05
commit
aaefaf5b06
2 changed files with 20 additions and 8 deletions
|
@ -98,7 +98,7 @@ namespace SourceGit.Git {
|
||||||
rs.Lines.Add(new LineChange(LineMode.Added, line.Substring(1), "", $"{newLine}"));
|
rs.Lines.Add(new LineChange(LineMode.Added, line.Substring(1), "", $"{newLine}"));
|
||||||
newLine++;
|
newLine++;
|
||||||
} else if (line[0] == '\\') {
|
} else if (line[0] == '\\') {
|
||||||
rs.Lines.Add(new LineChange(LineMode.Indicator, line.Substring(1)));
|
// IGNORE \ No new line end of file.
|
||||||
} else {
|
} else {
|
||||||
var match = REG_INDICATOR.Match(line);
|
var match = REG_INDICATOR.Match(line);
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
|
|
|
@ -44,6 +44,18 @@ namespace SourceGit.UI {
|
||||||
public FontStyle Style { get; set; }
|
public FontStyle Style { get; set; }
|
||||||
public string OldLine { get; set; }
|
public string OldLine { get; set; }
|
||||||
public string NewLine { get; set; }
|
public string NewLine { get; set; }
|
||||||
|
|
||||||
|
public bool IsContent {
|
||||||
|
get {
|
||||||
|
return Mode == Git.Diff.LineMode.Added || Mode == Git.Diff.LineMode.Deleted || Mode == Git.Diff.LineMode.Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsDifference {
|
||||||
|
get {
|
||||||
|
return Mode == Git.Diff.LineMode.Added || Mode == Git.Diff.LineMode.Deleted || Mode == Git.Diff.LineMode.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -148,8 +160,8 @@ namespace SourceGit.UI {
|
||||||
block.Content = line.Content;
|
block.Content = line.Content;
|
||||||
block.Mode = line.Mode;
|
block.Mode = line.Mode;
|
||||||
block.BG = GetLineBackground(line);
|
block.BG = GetLineBackground(line);
|
||||||
block.FG = line.Mode == Git.Diff.LineMode.Indicator ? fgIndicator : fgCommon;
|
block.FG = block.IsContent ? fgCommon : fgIndicator;
|
||||||
block.Style = line.Mode == Git.Diff.LineMode.Indicator ? FontStyles.Italic : FontStyles.Normal;
|
block.Style = block.IsContent ? FontStyles.Normal : FontStyles.Italic;
|
||||||
block.OldLine = line.OldLine;
|
block.OldLine = line.OldLine;
|
||||||
block.NewLine = line.NewLine;
|
block.NewLine = line.NewLine;
|
||||||
|
|
||||||
|
@ -199,8 +211,8 @@ namespace SourceGit.UI {
|
||||||
block.Content = line.Content;
|
block.Content = line.Content;
|
||||||
block.Mode = line.Mode;
|
block.Mode = line.Mode;
|
||||||
block.BG = GetLineBackground(line);
|
block.BG = GetLineBackground(line);
|
||||||
block.FG = line.Mode == Git.Diff.LineMode.Indicator ? fgIndicator : fgCommon;
|
block.FG = block.IsContent ? fgCommon : fgIndicator;
|
||||||
block.Style = line.Mode == Git.Diff.LineMode.Indicator ? FontStyles.Italic : FontStyles.Normal;
|
block.Style = block.IsContent ? FontStyles.Normal : FontStyles.Italic;
|
||||||
block.OldLine = line.OldLine;
|
block.OldLine = line.OldLine;
|
||||||
block.NewLine = line.NewLine;
|
block.NewLine = line.NewLine;
|
||||||
|
|
||||||
|
@ -548,7 +560,7 @@ namespace SourceGit.UI {
|
||||||
var first = grid.Items[firstVisible] as ChangeBlock;
|
var first = grid.Items[firstVisible] as ChangeBlock;
|
||||||
for (int i = firstVisible + 1; i < grid.Items.Count; i++) {
|
for (int i = firstVisible + 1; i < grid.Items.Count; i++) {
|
||||||
var next = grid.Items[i] as ChangeBlock;
|
var next = grid.Items[i] as ChangeBlock;
|
||||||
if (next.Mode != Git.Diff.LineMode.Normal && next.Mode != Git.Diff.LineMode.Indicator) {
|
if (next.IsDifference) {
|
||||||
if (firstModeEnded || next.Mode != first.Mode) {
|
if (firstModeEnded || next.Mode != first.Mode) {
|
||||||
scroller.ScrollToVerticalOffset(i);
|
scroller.ScrollToVerticalOffset(i);
|
||||||
break;
|
break;
|
||||||
|
@ -576,7 +588,7 @@ namespace SourceGit.UI {
|
||||||
var first = grid.Items[firstVisible] as ChangeBlock;
|
var first = grid.Items[firstVisible] as ChangeBlock;
|
||||||
for (int i = firstVisible - 1; i >= 0; i--) {
|
for (int i = firstVisible - 1; i >= 0; i--) {
|
||||||
var next = grid.Items[i] as ChangeBlock;
|
var next = grid.Items[i] as ChangeBlock;
|
||||||
if (next.Mode != Git.Diff.LineMode.Normal && next.Mode != Git.Diff.LineMode.Indicator) {
|
if (next.IsDifference) {
|
||||||
if (firstModeEnded || next.Mode != first.Mode) {
|
if (firstModeEnded || next.Mode != first.Mode) {
|
||||||
scroller.ScrollToVerticalOffset(i);
|
scroller.ScrollToVerticalOffset(i);
|
||||||
break;
|
break;
|
||||||
|
@ -619,7 +631,7 @@ namespace SourceGit.UI {
|
||||||
foreach (var item in items) {
|
foreach (var item in items) {
|
||||||
var block = item as ChangeBlock;
|
var block = item as ChangeBlock;
|
||||||
if (block == null) continue;
|
if (block == null) continue;
|
||||||
if (block.Mode == Git.Diff.LineMode.None || block.Mode == Git.Diff.LineMode.Indicator) continue;
|
if (!block.IsContent) continue;
|
||||||
|
|
||||||
builder.Append(block.Content);
|
builder.Append(block.Content);
|
||||||
builder.AppendLine();
|
builder.AppendLine();
|
||||||
|
|
Loading…
Reference in a new issue