2024-03-17 18:37:06 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia;
|
|
|
|
using Avalonia.Controls;
|
2024-02-19 23:44:26 -08:00
|
|
|
using Avalonia.Controls.Primitives;
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Media;
|
|
|
|
using Avalonia.Styling;
|
2024-02-27 05:13:52 -08:00
|
|
|
using Avalonia.VisualTree;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using AvaloniaEdit;
|
|
|
|
using AvaloniaEdit.Document;
|
|
|
|
using AvaloniaEdit.Editing;
|
|
|
|
using AvaloniaEdit.Rendering;
|
|
|
|
using AvaloniaEdit.TextMate;
|
|
|
|
using AvaloniaEdit.Utils;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using TextMateSharp.Grammars;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
|
|
|
public class CombinedTextDiffPresenter : TextEditor
|
|
|
|
{
|
|
|
|
public class LineNumberMargin : AbstractMargin
|
|
|
|
{
|
|
|
|
public LineNumberMargin(CombinedTextDiffPresenter editor, bool isOldLine)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
_isOldLine = isOldLine;
|
|
|
|
ClipToBounds = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public override void Render(DrawingContext context)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
if (_editor.DiffData == null) return;
|
|
|
|
|
|
|
|
var view = TextView;
|
2024-03-17 18:37:06 -07:00
|
|
|
if (view != null && view.VisualLinesValid)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var typeface = view.CreateTypeface();
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var line in view.VisualLines)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var index = line.FirstDocumentLine.LineNumber;
|
|
|
|
if (index > _editor.DiffData.Lines.Count) break;
|
|
|
|
|
|
|
|
var info = _editor.DiffData.Lines[index - 1];
|
|
|
|
var lineNumber = _isOldLine ? info.OldLine : info.NewLine;
|
|
|
|
if (string.IsNullOrEmpty(lineNumber)) continue;
|
|
|
|
|
|
|
|
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
|
|
|
|
var txt = new FormattedText(
|
|
|
|
lineNumber,
|
|
|
|
CultureInfo.CurrentCulture,
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
typeface,
|
|
|
|
_editor.FontSize,
|
|
|
|
_editor.Foreground);
|
|
|
|
context.DrawText(txt, new Point(Bounds.Width - txt.Width, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
|
|
{
|
|
|
|
if (_editor.DiffData == null || TextView == null)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
return new Size(32, 0);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var typeface = TextView.CreateTypeface();
|
|
|
|
var test = new FormattedText(
|
|
|
|
$"{_editor.DiffData.MaxLineNumber}",
|
|
|
|
CultureInfo.CurrentCulture,
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
typeface,
|
|
|
|
_editor.FontSize,
|
|
|
|
Brushes.White);
|
|
|
|
return new Size(test.Width, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly CombinedTextDiffPresenter _editor;
|
|
|
|
private readonly bool _isOldLine;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class VerticalSeperatorMargin : AbstractMargin
|
|
|
|
{
|
|
|
|
public VerticalSeperatorMargin(CombinedTextDiffPresenter editor)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public override void Render(DrawingContext context)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var pen = new Pen(_editor.BorderBrush, 1);
|
|
|
|
context.DrawLine(pen, new Point(0, 0), new Point(0, Bounds.Height));
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
return new Size(1, 0);
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly CombinedTextDiffPresenter _editor = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class LineBackgroundRenderer : IBackgroundRenderer
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
private static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));
|
|
|
|
private static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(60, 0, 255, 0));
|
|
|
|
private static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(60, 255, 0, 0));
|
|
|
|
|
|
|
|
public KnownLayer Layer => KnownLayer.Background;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public LineBackgroundRenderer(CombinedTextDiffPresenter editor)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public void Draw(TextView textView, DrawingContext drawingContext)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
if (_editor.Document == null || !textView.VisualLinesValid) return;
|
|
|
|
|
|
|
|
var width = textView.Bounds.Width;
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var line in textView.VisualLines)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var index = line.FirstDocumentLine.LineNumber;
|
|
|
|
if (index > _editor.DiffData.Lines.Count) break;
|
|
|
|
|
|
|
|
var info = _editor.DiffData.Lines[index - 1];
|
|
|
|
var bg = GetBrushByLineType(info.Type);
|
|
|
|
if (bg == null) continue;
|
|
|
|
|
|
|
|
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - textView.VerticalOffset;
|
|
|
|
drawingContext.DrawRectangle(bg, null, new Rect(0, y, width, line.Height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private IBrush GetBrushByLineType(Models.TextDiffLineType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Models.TextDiffLineType.None: return BG_EMPTY;
|
|
|
|
case Models.TextDiffLineType.Added: return BG_ADDED;
|
|
|
|
case Models.TextDiffLineType.Deleted: return BG_DELETED;
|
|
|
|
default: return null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly CombinedTextDiffPresenter _editor = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class LineStyleTransformer : DocumentColorizingTransformer
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
private static readonly Brush HL_ADDED = new SolidColorBrush(Color.FromArgb(90, 0, 255, 0));
|
|
|
|
private static readonly Brush HL_DELETED = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public LineStyleTransformer(CombinedTextDiffPresenter editor, IBrush indicatorFG)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
_indicatorFG = indicatorFG;
|
2024-03-04 23:53:38 -08:00
|
|
|
_indicatorTypeface = new Typeface("fonts:SourceGit#JetBrains Mono", FontStyle.Italic);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void ColorizeLine(DocumentLine line)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var idx = line.LineNumber;
|
|
|
|
if (idx > _editor.DiffData.Lines.Count) return;
|
|
|
|
|
|
|
|
var info = _editor.DiffData.Lines[idx - 1];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (info.Type == Models.TextDiffLineType.Indicator)
|
|
|
|
{
|
|
|
|
ChangeLinePart(line.Offset, line.EndOffset, v =>
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
v.TextRunProperties.SetForegroundBrush(_indicatorFG);
|
|
|
|
v.TextRunProperties.SetTypeface(_indicatorTypeface);
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (info.Highlights.Count > 0)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var bg = info.Type == Models.TextDiffLineType.Added ? HL_ADDED : HL_DELETED;
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var highlight in info.Highlights)
|
|
|
|
{
|
|
|
|
ChangeLinePart(line.Offset + highlight.Start, line.Offset + highlight.Start + highlight.Count, v =>
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
v.TextRunProperties.SetBackgroundBrush(bg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly CombinedTextDiffPresenter _editor;
|
|
|
|
private readonly IBrush _indicatorFG = Brushes.DarkGray;
|
|
|
|
private readonly Typeface _indicatorTypeface = Typeface.Default;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<Models.TextDiff> DiffDataProperty =
|
|
|
|
AvaloniaProperty.Register<CombinedTextDiffPresenter, Models.TextDiff>(nameof(DiffData));
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public Models.TextDiff DiffData
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(DiffDataProperty);
|
|
|
|
set => SetValue(DiffDataProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<IBrush> SecondaryFGProperty =
|
|
|
|
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(SecondaryFG), Brushes.Gray);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public IBrush SecondaryFG
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(SecondaryFGProperty);
|
|
|
|
set => SetValue(SecondaryFGProperty, value);
|
|
|
|
}
|
|
|
|
|
2024-02-28 19:29:54 -08:00
|
|
|
public static readonly StyledProperty<Vector> SyncScrollOffsetProperty =
|
|
|
|
AvaloniaProperty.Register<SingleSideTextDiffPresenter, Vector>(nameof(SyncScrollOffset));
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public Vector SyncScrollOffset
|
|
|
|
{
|
2024-02-28 19:29:54 -08:00
|
|
|
get => GetValue(SyncScrollOffsetProperty);
|
|
|
|
set => SetValue(SyncScrollOffsetProperty, value);
|
|
|
|
}
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
protected override Type StyleKeyOverride => typeof(TextEditor);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public CombinedTextDiffPresenter() : base(new TextArea(), new TextDocument())
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
IsReadOnly = true;
|
|
|
|
ShowLineNumbers = false;
|
|
|
|
WordWrap = false;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnLoaded(RoutedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnLoaded(e);
|
|
|
|
|
|
|
|
TextArea.LeftMargins.Add(new LineNumberMargin(this, true) { Margin = new Thickness(8, 0) });
|
|
|
|
TextArea.LeftMargins.Add(new VerticalSeperatorMargin(this));
|
|
|
|
TextArea.LeftMargins.Add(new LineNumberMargin(this, false) { Margin = new Thickness(8, 0) });
|
|
|
|
TextArea.LeftMargins.Add(new VerticalSeperatorMargin(this));
|
|
|
|
|
|
|
|
TextArea.TextView.Margin = new Thickness(4, 0);
|
|
|
|
TextArea.TextView.BackgroundRenderers.Add(new LineBackgroundRenderer(this));
|
|
|
|
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
2024-02-28 19:29:54 -08:00
|
|
|
TextArea.TextView.ScrollOffsetChanged += OnTextViewScrollOffsetChanged;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_registryOptions = new RegistryOptions(ThemeName.DarkPlus);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_registryOptions = new RegistryOptions(ThemeName.LightPlus);
|
|
|
|
}
|
|
|
|
|
|
|
|
_textMate = this.InstallTextMate(_registryOptions);
|
2024-02-22 04:47:43 -08:00
|
|
|
UpdateGrammar();
|
2024-03-04 23:53:38 -08:00
|
|
|
|
|
|
|
// This line must after InstallTextMate.
|
|
|
|
TextArea.TextView.LineTransformers.Add(new LineStyleTransformer(this, SecondaryFG));
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnUnloaded(RoutedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnUnloaded(e);
|
|
|
|
|
|
|
|
TextArea.LeftMargins.Clear();
|
|
|
|
TextArea.TextView.BackgroundRenderers.Clear();
|
|
|
|
TextArea.TextView.LineTransformers.Clear();
|
|
|
|
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
2024-02-28 19:29:54 -08:00
|
|
|
TextArea.TextView.ScrollOffsetChanged -= OnTextViewScrollOffsetChanged;
|
2024-02-05 23:08:37 -08:00
|
|
|
_registryOptions = null;
|
|
|
|
_textMate.Dispose();
|
|
|
|
_textMate = null;
|
|
|
|
GC.Collect();
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var selection = TextArea.Selection;
|
|
|
|
if (selection.IsEmpty) return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-02-27 05:13:52 -08:00
|
|
|
var menu = new ContextMenu();
|
|
|
|
var parentView = this.FindAncestorOfType<TextDiffView>();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (parentView != null)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
parentView.FillContextMenuForWorkingCopyChange(menu, selection.StartPosition.Line, selection.EndPosition.Line, false);
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
var copy = new MenuItem();
|
|
|
|
copy.Header = App.Text("Copy");
|
2024-02-27 05:13:52 -08:00
|
|
|
copy.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-03-17 18:37:06 -07:00
|
|
|
copy.Click += (o, ev) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
App.CopyText(SelectedText);
|
2024-02-05 23:08:37 -08:00
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(copy);
|
|
|
|
menu.Open(TextArea.TextView);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnTextViewScrollOffsetChanged(object sender, EventArgs e)
|
|
|
|
{
|
2024-02-28 19:29:54 -08:00
|
|
|
SyncScrollOffset = TextArea.TextView.ScrollOffset;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnPropertyChanged(change);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (change.Property == DiffDataProperty)
|
|
|
|
{
|
|
|
|
if (DiffData != null)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var builder = new StringBuilder();
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var line in DiffData.Lines)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
builder.AppendLine(line.Content);
|
|
|
|
}
|
|
|
|
|
2024-02-22 04:47:43 -08:00
|
|
|
UpdateGrammar();
|
2024-02-27 05:13:52 -08:00
|
|
|
Text = builder.ToString();
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
Text = string.Empty;
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (change.Property == SyncScrollOffsetProperty)
|
|
|
|
{
|
|
|
|
if (TextArea.TextView.ScrollOffset != SyncScrollOffset)
|
|
|
|
{
|
2024-02-28 19:29:54 -08:00
|
|
|
IScrollable scrollable = TextArea.TextView;
|
|
|
|
scrollable.Offset = SyncScrollOffset;
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (change.Property.Name == "ActualThemeVariant" && change.NewValue != null && _textMate != null)
|
|
|
|
{
|
|
|
|
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_textMate.SetTheme(_registryOptions.LoadTheme(ThemeName.DarkPlus));
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_textMate.SetTheme(_registryOptions.LoadTheme(ThemeName.LightPlus));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void UpdateGrammar()
|
|
|
|
{
|
2024-02-22 04:47:43 -08:00
|
|
|
if (_textMate == null || DiffData == null) return;
|
|
|
|
|
|
|
|
var ext = Path.GetExtension(DiffData.File);
|
2024-03-17 18:37:06 -07:00
|
|
|
if (ext == ".h")
|
|
|
|
{
|
2024-02-22 04:47:43 -08:00
|
|
|
_textMate.SetGrammar(_registryOptions.GetScopeByLanguageId("cpp"));
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-22 04:47:43 -08:00
|
|
|
_textMate.SetGrammar(_registryOptions.GetScopeByExtension(ext));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
private RegistryOptions _registryOptions;
|
|
|
|
private TextMate.Installation _textMate;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class SingleSideTextDiffPresenter : TextEditor
|
|
|
|
{
|
|
|
|
public class LineNumberMargin : AbstractMargin
|
|
|
|
{
|
|
|
|
public LineNumberMargin(SingleSideTextDiffPresenter editor)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
ClipToBounds = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public override void Render(DrawingContext context)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
if (_editor.DiffData == null) return;
|
|
|
|
|
|
|
|
var view = TextView;
|
2024-03-17 18:37:06 -07:00
|
|
|
if (view != null && view.VisualLinesValid)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var typeface = view.CreateTypeface();
|
|
|
|
var infos = _editor.IsOld ? _editor.DiffData.Old : _editor.DiffData.New;
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var line in view.VisualLines)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var index = line.FirstDocumentLine.LineNumber;
|
|
|
|
if (index > infos.Count) break;
|
|
|
|
|
|
|
|
var info = infos[index - 1];
|
|
|
|
var lineNumber = _editor.IsOld ? info.OldLine : info.NewLine;
|
|
|
|
if (string.IsNullOrEmpty(lineNumber)) continue;
|
|
|
|
|
|
|
|
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
|
|
|
|
var txt = new FormattedText(
|
|
|
|
lineNumber,
|
|
|
|
CultureInfo.CurrentCulture,
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
typeface,
|
|
|
|
_editor.FontSize,
|
|
|
|
_editor.Foreground);
|
|
|
|
context.DrawText(txt, new Point(Bounds.Width - txt.Width, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
|
|
{
|
|
|
|
if (_editor.DiffData == null || TextView == null)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
return new Size(32, 0);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var typeface = TextView.CreateTypeface();
|
|
|
|
var test = new FormattedText(
|
|
|
|
$"{_editor.DiffData.MaxLineNumber}",
|
|
|
|
CultureInfo.CurrentCulture,
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
typeface,
|
|
|
|
_editor.FontSize,
|
|
|
|
Brushes.White);
|
|
|
|
return new Size(test.Width, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly SingleSideTextDiffPresenter _editor;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class VerticalSeperatorMargin : AbstractMargin
|
|
|
|
{
|
|
|
|
public VerticalSeperatorMargin(SingleSideTextDiffPresenter editor)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public override void Render(DrawingContext context)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var pen = new Pen(_editor.BorderBrush, 1);
|
|
|
|
context.DrawLine(pen, new Point(0, 0), new Point(0, Bounds.Height));
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
return new Size(1, 0);
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly SingleSideTextDiffPresenter _editor = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class LineBackgroundRenderer : IBackgroundRenderer
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
private static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));
|
|
|
|
private static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(60, 0, 255, 0));
|
|
|
|
private static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(60, 255, 0, 0));
|
|
|
|
|
|
|
|
public KnownLayer Layer => KnownLayer.Background;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public LineBackgroundRenderer(SingleSideTextDiffPresenter editor)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public void Draw(TextView textView, DrawingContext drawingContext)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
if (_editor.Document == null || !textView.VisualLinesValid) return;
|
|
|
|
|
|
|
|
var width = textView.Bounds.Width;
|
|
|
|
var infos = _editor.IsOld ? _editor.DiffData.Old : _editor.DiffData.New;
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var line in textView.VisualLines)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var index = line.FirstDocumentLine.LineNumber;
|
|
|
|
if (index > infos.Count) break;
|
|
|
|
|
|
|
|
var info = infos[index - 1];
|
|
|
|
var bg = GetBrushByLineType(info.Type);
|
|
|
|
if (bg == null) continue;
|
|
|
|
|
|
|
|
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - textView.VerticalOffset;
|
|
|
|
drawingContext.DrawRectangle(bg, null, new Rect(0, y, width, line.Height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private IBrush GetBrushByLineType(Models.TextDiffLineType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Models.TextDiffLineType.None: return BG_EMPTY;
|
|
|
|
case Models.TextDiffLineType.Added: return BG_ADDED;
|
|
|
|
case Models.TextDiffLineType.Deleted: return BG_DELETED;
|
|
|
|
default: return null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly SingleSideTextDiffPresenter _editor = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public class LineStyleTransformer : DocumentColorizingTransformer
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
private static readonly Brush HL_ADDED = new SolidColorBrush(Color.FromArgb(90, 0, 255, 0));
|
|
|
|
private static readonly Brush HL_DELETED = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public LineStyleTransformer(SingleSideTextDiffPresenter editor, IBrush indicatorFG)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_editor = editor;
|
|
|
|
_indicatorFG = indicatorFG;
|
2024-03-04 23:53:38 -08:00
|
|
|
_indicatorTypeface = new Typeface("fonts:SourceGit#JetBrains Mono", FontStyle.Italic);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void ColorizeLine(DocumentLine line)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var infos = _editor.IsOld ? _editor.DiffData.Old : _editor.DiffData.New;
|
|
|
|
var idx = line.LineNumber;
|
|
|
|
if (idx > infos.Count) return;
|
|
|
|
|
|
|
|
var info = infos[idx - 1];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (info.Type == Models.TextDiffLineType.Indicator)
|
|
|
|
{
|
|
|
|
ChangeLinePart(line.Offset, line.EndOffset, v =>
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
v.TextRunProperties.SetForegroundBrush(_indicatorFG);
|
|
|
|
v.TextRunProperties.SetTypeface(_indicatorTypeface);
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (info.Highlights.Count > 0)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var bg = info.Type == Models.TextDiffLineType.Added ? HL_ADDED : HL_DELETED;
|
2024-03-17 18:37:06 -07:00
|
|
|
foreach (var highlight in info.Highlights)
|
|
|
|
{
|
|
|
|
ChangeLinePart(line.Offset + highlight.Start, line.Offset + highlight.Start + highlight.Count, v =>
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
v.TextRunProperties.SetBackgroundBrush(bg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private readonly SingleSideTextDiffPresenter _editor;
|
|
|
|
private readonly IBrush _indicatorFG = Brushes.DarkGray;
|
|
|
|
private readonly Typeface _indicatorTypeface = Typeface.Default;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<bool> IsOldProperty =
|
|
|
|
AvaloniaProperty.Register<SingleSideTextDiffPresenter, bool>(nameof(IsOld));
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public bool IsOld
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(IsOldProperty);
|
|
|
|
set => SetValue(IsOldProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<ViewModels.TwoSideTextDiff> DiffDataProperty =
|
|
|
|
AvaloniaProperty.Register<SingleSideTextDiffPresenter, ViewModels.TwoSideTextDiff>(nameof(DiffData));
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public ViewModels.TwoSideTextDiff DiffData
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(DiffDataProperty);
|
|
|
|
set => SetValue(DiffDataProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<IBrush> SecondaryFGProperty =
|
|
|
|
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(SecondaryFG), Brushes.Gray);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public IBrush SecondaryFG
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(SecondaryFGProperty);
|
|
|
|
set => SetValue(SecondaryFGProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<Vector> SyncScrollOffsetProperty =
|
2024-03-12 00:50:00 -07:00
|
|
|
AvaloniaProperty.Register<SingleSideTextDiffPresenter, Vector>(nameof(SyncScrollOffset), Vector.Zero);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public Vector SyncScrollOffset
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(SyncScrollOffsetProperty);
|
|
|
|
set => SetValue(SyncScrollOffsetProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Type StyleKeyOverride => typeof(TextEditor);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public SingleSideTextDiffPresenter() : base(new TextArea(), new TextDocument())
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
IsReadOnly = true;
|
|
|
|
ShowLineNumbers = false;
|
2024-02-27 05:13:52 -08:00
|
|
|
WordWrap = false;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnLoaded(RoutedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnLoaded(e);
|
|
|
|
|
2024-03-12 00:50:00 -07:00
|
|
|
_scrollViewer = this.FindDescendantOfType<ScrollViewer>();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (_scrollViewer != null)
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
_scrollViewer.Offset = SyncScrollOffset;
|
|
|
|
_scrollViewer.ScrollChanged += OnTextViewScrollChanged;
|
|
|
|
}
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
TextArea.LeftMargins.Add(new LineNumberMargin(this) { Margin = new Thickness(8, 0) });
|
|
|
|
TextArea.LeftMargins.Add(new VerticalSeperatorMargin(this));
|
|
|
|
TextArea.TextView.Margin = new Thickness(4, 0);
|
|
|
|
TextArea.TextView.BackgroundRenderers.Add(new LineBackgroundRenderer(this));
|
|
|
|
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_registryOptions = new RegistryOptions(ThemeName.DarkPlus);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_registryOptions = new RegistryOptions(ThemeName.LightPlus);
|
|
|
|
}
|
|
|
|
|
|
|
|
_textMate = this.InstallTextMate(_registryOptions);
|
2024-02-22 04:47:43 -08:00
|
|
|
UpdateGrammar();
|
2024-03-04 23:53:38 -08:00
|
|
|
|
|
|
|
// This line must after InstallTextMate
|
|
|
|
TextArea.TextView.LineTransformers.Add(new LineStyleTransformer(this, SecondaryFG));
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnUnloaded(RoutedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnUnloaded(e);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (_scrollViewer != null)
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
_scrollViewer.ScrollChanged -= OnTextViewScrollChanged;
|
|
|
|
_scrollViewer = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-03-12 00:50:00 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
TextArea.LeftMargins.Clear();
|
|
|
|
TextArea.TextView.BackgroundRenderers.Clear();
|
|
|
|
TextArea.TextView.LineTransformers.Clear();
|
|
|
|
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
|
|
|
_registryOptions = null;
|
|
|
|
_textMate.Dispose();
|
|
|
|
_textMate = null;
|
|
|
|
GC.Collect();
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (_syncScrollingByOthers)
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
_syncScrollingByOthers = false;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
SyncScrollOffset = _scrollViewer.Offset;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var selection = TextArea.Selection;
|
|
|
|
if (selection.IsEmpty) return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-02-27 05:13:52 -08:00
|
|
|
var menu = new ContextMenu();
|
|
|
|
var parentView = this.FindAncestorOfType<TextDiffView>();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (parentView != null)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
parentView.FillContextMenuForWorkingCopyChange(menu, selection.StartPosition.Line, selection.EndPosition.Line, IsOld);
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
var copy = new MenuItem();
|
|
|
|
copy.Header = App.Text("Copy");
|
2024-02-27 05:13:52 -08:00
|
|
|
copy.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-03-17 18:37:06 -07:00
|
|
|
copy.Click += (o, ev) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
App.CopyText(SelectedText);
|
2024-02-05 23:08:37 -08:00
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(copy);
|
|
|
|
menu.Open(TextArea.TextView);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnPropertyChanged(change);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (change.Property == DiffDataProperty)
|
|
|
|
{
|
|
|
|
if (DiffData != null)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var builder = new StringBuilder();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (IsOld)
|
|
|
|
{
|
|
|
|
foreach (var line in DiffData.Old)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
builder.AppendLine(line.Content);
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach (var line in DiffData.New)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
builder.AppendLine(line.Content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 04:47:43 -08:00
|
|
|
UpdateGrammar();
|
2024-02-05 23:08:37 -08:00
|
|
|
Text = builder.ToString();
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
Text = string.Empty;
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (change.Property == SyncScrollOffsetProperty)
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
if (_scrollViewer == null) return;
|
|
|
|
|
|
|
|
var curOffset = _scrollViewer.Offset;
|
2024-03-17 18:37:06 -07:00
|
|
|
if (!curOffset.Equals(SyncScrollOffset))
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
_syncScrollingByOthers = true;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
|
|
if (curOffset.X != SyncScrollOffset.X)
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
var offset = new Vector(Math.Min(_scrollViewer.ScrollBarMaximum.X, SyncScrollOffset.X), SyncScrollOffset.Y);
|
|
|
|
_scrollViewer.Offset = offset;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-12 00:50:00 -07:00
|
|
|
_scrollViewer.Offset = SyncScrollOffset;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (change.Property.Name == "ActualThemeVariant" && change.NewValue != null && _textMate != null)
|
|
|
|
{
|
|
|
|
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_textMate.SetTheme(_registryOptions.LoadTheme(ThemeName.DarkPlus));
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
_textMate.SetTheme(_registryOptions.LoadTheme(ThemeName.LightPlus));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void UpdateGrammar()
|
|
|
|
{
|
2024-02-22 04:47:43 -08:00
|
|
|
if (_textMate == null || DiffData == null) return;
|
|
|
|
|
|
|
|
var ext = Path.GetExtension(DiffData.File);
|
2024-03-17 18:37:06 -07:00
|
|
|
if (ext == ".h")
|
|
|
|
{
|
2024-02-22 04:47:43 -08:00
|
|
|
_textMate.SetGrammar(_registryOptions.GetScopeByLanguageId("cpp"));
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-22 04:47:43 -08:00
|
|
|
_textMate.SetGrammar(_registryOptions.GetScopeByExtension(ext));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
private RegistryOptions _registryOptions;
|
|
|
|
private TextMate.Installation _textMate;
|
2024-03-12 00:50:00 -07:00
|
|
|
|
|
|
|
private ScrollViewer _scrollViewer = null;
|
|
|
|
private bool _syncScrollingByOthers = false;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public partial class TextDiffView : UserControl
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
public static readonly StyledProperty<Models.TextDiff> TextDiffProperty =
|
|
|
|
AvaloniaProperty.Register<TextDiffView, Models.TextDiff>(nameof(TextDiff), null);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public Models.TextDiff TextDiff
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
get => GetValue(TextDiffProperty);
|
|
|
|
set => SetValue(TextDiffProperty, value);
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:08:01 -07:00
|
|
|
public static readonly StyledProperty<bool> UseSideBySideDiffProperty =
|
|
|
|
AvaloniaProperty.Register<TextDiffView, bool>(nameof(UseSideBySideDiff), false);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-19 22:08:01 -07:00
|
|
|
public bool UseSideBySideDiff
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-03-19 22:08:01 -07:00
|
|
|
get => GetValue(UseSideBySideDiffProperty);
|
|
|
|
set => SetValue(UseSideBySideDiffProperty, value);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public TextDiffView()
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public void FillContextMenuForWorkingCopyChange(ContextMenu menu, int startLine, int endLine, bool isOldSide)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var parentView = this.FindAncestorOfType<DiffView>();
|
|
|
|
if (parentView == null) return;
|
|
|
|
|
|
|
|
var ctx = parentView.DataContext as ViewModels.DiffContext;
|
|
|
|
if (ctx == null) return;
|
|
|
|
|
|
|
|
var change = ctx.WorkingCopyChange;
|
|
|
|
if (change == null) return;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (startLine > endLine)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var tmp = startLine;
|
|
|
|
startLine = endLine;
|
|
|
|
endLine = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
var selection = GetUnifiedSelection(startLine, endLine, isOldSide);
|
|
|
|
if (!selection.HasChanges) return;
|
|
|
|
|
|
|
|
// If all changes has been selected the use method provided by ViewModels.WorkingCopy.
|
|
|
|
// Otherwise, use `git apply`
|
2024-03-17 18:37:06 -07:00
|
|
|
if (!selection.HasLeftChanges)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var workcopyView = this.FindAncestorOfType<WorkingCopy>();
|
|
|
|
if (workcopyView == null) return;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (ctx.IsUnstaged)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var stage = new MenuItem();
|
|
|
|
stage.Header = App.Text("FileCM.StageSelectedLines");
|
|
|
|
stage.Icon = App.CreateMenuIcon("Icons.File.Add");
|
2024-03-17 18:37:06 -07:00
|
|
|
stage.Click += (_, e) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
|
|
|
workcopy.StageChanges(new List<Models.Change> { change });
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var discard = new MenuItem();
|
|
|
|
discard.Header = App.Text("FileCM.DiscardSelectedLines");
|
|
|
|
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
2024-03-17 18:37:06 -07:00
|
|
|
discard.Click += (_, e) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
2024-02-29 19:34:32 -08:00
|
|
|
workcopy.Discard(new List<Models.Change> { change }, true);
|
2024-02-27 05:13:52 -08:00
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(stage);
|
|
|
|
menu.Items.Add(discard);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var unstage = new MenuItem();
|
|
|
|
unstage.Header = App.Text("FileCM.UnstageSelectedLines");
|
|
|
|
unstage.Icon = App.CreateMenuIcon("Icons.File.Remove");
|
2024-03-17 18:37:06 -07:00
|
|
|
unstage.Click += (_, e) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
|
|
|
workcopy.UnstageChanges(new List<Models.Change> { change });
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
2024-02-28 18:59:59 -08:00
|
|
|
|
|
|
|
var discard = new MenuItem();
|
|
|
|
discard.Header = App.Text("FileCM.DiscardSelectedLines");
|
|
|
|
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
2024-03-17 18:37:06 -07:00
|
|
|
discard.Click += (_, e) =>
|
|
|
|
{
|
2024-02-29 19:34:32 -08:00
|
|
|
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
|
|
|
workcopy.Discard(new List<Models.Change> { change }, false);
|
2024-02-28 18:59:59 -08:00
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
2024-02-27 05:13:52 -08:00
|
|
|
menu.Items.Add(unstage);
|
2024-02-28 18:59:59 -08:00
|
|
|
menu.Items.Add(discard);
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var repoView = this.FindAncestorOfType<Repository>();
|
|
|
|
if (repoView == null) return;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (ctx.IsUnstaged)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var stage = new MenuItem();
|
|
|
|
stage.Header = App.Text("FileCM.StageSelectedLines");
|
|
|
|
stage.Icon = App.CreateMenuIcon("Icons.File.Add");
|
2024-03-17 18:37:06 -07:00
|
|
|
stage.Click += (_, e) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var repo = repoView.DataContext as ViewModels.Repository;
|
|
|
|
repo.SetWatcherEnabled(false);
|
|
|
|
|
|
|
|
var tmpFile = Path.GetTempFileName();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (change.WorkTree == Models.ChangeState.Untracked)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GenerateNewPatchFromSelection(change, null, selection, false, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-03-19 22:08:01 -07:00
|
|
|
else if (!UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, false, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
|
|
|
TextDiff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, false, isOldSide, tmpFile);
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--cache --index").Exec();
|
|
|
|
File.Delete(tmpFile);
|
|
|
|
|
2024-03-07 17:57:29 -08:00
|
|
|
repo.MarkWorkingCopyDirtyManually();
|
2024-02-27 05:13:52 -08:00
|
|
|
repo.SetWatcherEnabled(true);
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var discard = new MenuItem();
|
|
|
|
discard.Header = App.Text("FileCM.DiscardSelectedLines");
|
|
|
|
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
2024-03-17 18:37:06 -07:00
|
|
|
discard.Click += (_, e) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var repo = repoView.DataContext as ViewModels.Repository;
|
|
|
|
repo.SetWatcherEnabled(false);
|
|
|
|
|
|
|
|
var tmpFile = Path.GetTempFileName();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (change.WorkTree == Models.ChangeState.Untracked)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GenerateNewPatchFromSelection(change, null, selection, true, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-03-19 22:08:01 -07:00
|
|
|
else if (!UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
|
|
|
TextDiff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, isOldSide, tmpFile);
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--reverse").Exec();
|
|
|
|
File.Delete(tmpFile);
|
|
|
|
|
2024-03-07 17:57:29 -08:00
|
|
|
repo.MarkWorkingCopyDirtyManually();
|
2024-02-27 05:13:52 -08:00
|
|
|
repo.SetWatcherEnabled(true);
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(stage);
|
|
|
|
menu.Items.Add(discard);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var unstage = new MenuItem();
|
|
|
|
unstage.Header = App.Text("FileCM.UnstageSelectedLines");
|
|
|
|
unstage.Icon = App.CreateMenuIcon("Icons.File.Remove");
|
2024-03-17 18:37:06 -07:00
|
|
|
unstage.Click += (_, e) =>
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var repo = repoView.DataContext as ViewModels.Repository;
|
|
|
|
repo.SetWatcherEnabled(false);
|
|
|
|
|
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
|
|
|
var tmpFile = Path.GetTempFileName();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (change.Index == Models.ChangeState.Added)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GenerateNewPatchFromSelection(change, treeGuid, selection, true, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-03-19 22:08:01 -07:00
|
|
|
else if (!UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
TextDiff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, isOldSide, tmpFile);
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--cache --index --reverse").Exec();
|
|
|
|
File.Delete(tmpFile);
|
|
|
|
|
2024-03-07 17:57:29 -08:00
|
|
|
repo.MarkWorkingCopyDirtyManually();
|
2024-02-27 05:13:52 -08:00
|
|
|
repo.SetWatcherEnabled(true);
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
2024-02-28 18:59:59 -08:00
|
|
|
|
|
|
|
var discard = new MenuItem();
|
|
|
|
discard.Header = App.Text("FileCM.DiscardSelectedLines");
|
|
|
|
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
2024-03-17 18:37:06 -07:00
|
|
|
discard.Click += (_, e) =>
|
|
|
|
{
|
2024-02-28 18:59:59 -08:00
|
|
|
var repo = repoView.DataContext as ViewModels.Repository;
|
|
|
|
repo.SetWatcherEnabled(false);
|
|
|
|
|
|
|
|
var tmpFile = Path.GetTempFileName();
|
2024-03-17 18:37:06 -07:00
|
|
|
if (change.WorkTree == Models.ChangeState.Untracked)
|
|
|
|
{
|
2024-02-28 18:59:59 -08:00
|
|
|
TextDiff.GenerateNewPatchFromSelection(change, null, selection, true, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-03-19 22:08:01 -07:00
|
|
|
else if (!UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-28 18:59:59 -08:00
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
|
|
|
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-28 18:59:59 -08:00
|
|
|
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
|
|
|
|
TextDiff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, isOldSide, tmpFile);
|
|
|
|
}
|
|
|
|
|
2024-03-02 17:16:19 -08:00
|
|
|
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--index --reverse").Exec();
|
2024-02-28 18:59:59 -08:00
|
|
|
File.Delete(tmpFile);
|
|
|
|
|
2024-03-07 17:57:29 -08:00
|
|
|
repo.MarkWorkingCopyDirtyManually();
|
2024-02-28 18:59:59 -08:00
|
|
|
repo.SetWatcherEnabled(true);
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
2024-02-27 05:13:52 -08:00
|
|
|
menu.Items.Add(unstage);
|
2024-02-28 18:59:59 -08:00
|
|
|
menu.Items.Add(discard);
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnPropertyChanged(change);
|
|
|
|
|
2024-03-19 22:08:01 -07:00
|
|
|
if (change.Property == TextDiffProperty || change.Property == UseSideBySideDiffProperty)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
if (TextDiff == null)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
Content = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-03-19 22:08:01 -07:00
|
|
|
else if (UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-03-19 22:08:01 -07:00
|
|
|
Content = new ViewModels.TwoSideTextDiff(TextDiff);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 22:08:01 -07:00
|
|
|
Content = TextDiff;
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private Models.TextDiffSelection GetUnifiedSelection(int startLine, int endLine, bool isOldSide)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var rs = new Models.TextDiffSelection();
|
|
|
|
var diff = TextDiff;
|
2024-02-27 05:13:52 -08:00
|
|
|
|
2024-02-28 20:16:31 -08:00
|
|
|
endLine = Math.Min(endLine, TextDiff.Lines.Count);
|
2024-03-17 18:37:06 -07:00
|
|
|
if (Content is ViewModels.TwoSideTextDiff twoSides)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var target = isOldSide ? twoSides.Old : twoSides.New;
|
|
|
|
var firstContentLine = -1;
|
2024-03-17 18:37:06 -07:00
|
|
|
for (int i = startLine - 1; i < endLine; i++)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var line = target[i];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (line.Type != Models.TextDiffLineType.None)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
firstContentLine = i;
|
2024-02-27 05:13:52 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 02:15:40 -08:00
|
|
|
if (firstContentLine < 0) return rs;
|
|
|
|
|
|
|
|
var endContentLine = -1;
|
2024-03-17 18:37:06 -07:00
|
|
|
for (int i = Math.Min(endLine - 1, target.Count - 1); i >= startLine - 1; i--)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var line = target[i];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (line.Type != Models.TextDiffLineType.None)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
endContentLine = i;
|
|
|
|
break;
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 02:15:40 -08:00
|
|
|
if (endContentLine < 0) return rs;
|
2024-02-27 05:13:52 -08:00
|
|
|
|
2024-02-28 02:15:40 -08:00
|
|
|
var firstContent = target[firstContentLine];
|
|
|
|
var endContent = target[endContentLine];
|
|
|
|
startLine = TextDiff.Lines.IndexOf(firstContent) + 1;
|
|
|
|
endLine = TextDiff.Lines.IndexOf(endContent) + 1;
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.StartLine = startLine;
|
|
|
|
rs.EndLine = endLine;
|
2024-02-27 05:13:52 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
for (int i = 0; i < startLine - 1; i++)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var line = diff.Lines[i];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (line.Type == Models.TextDiffLineType.Added)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasLeftChanges = true;
|
|
|
|
rs.IgnoredAdds++;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (line.Type == Models.TextDiffLineType.Deleted)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasLeftChanges = true;
|
|
|
|
rs.IgnoredDeletes++;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
2024-02-27 05:13:52 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
for (int i = startLine - 1; i < endLine; i++)
|
|
|
|
{
|
2024-02-27 05:13:52 -08:00
|
|
|
var line = diff.Lines[i];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (line.Type == Models.TextDiffLineType.Added)
|
|
|
|
{
|
2024-03-19 22:08:01 -07:00
|
|
|
if (!UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasChanges = true;
|
2024-02-27 05:13:52 -08:00
|
|
|
break;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (isOldSide)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasLeftChanges = true;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasChanges = true;
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (line.Type == Models.TextDiffLineType.Deleted)
|
|
|
|
{
|
2024-03-19 22:08:01 -07:00
|
|
|
if (!UseSideBySideDiff)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasChanges = true;
|
|
|
|
break;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (isOldSide)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasChanges = true;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasLeftChanges = true;
|
|
|
|
}
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (!rs.HasLeftChanges)
|
|
|
|
{
|
|
|
|
for (int i = endLine; i < diff.Lines.Count; i++)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
var line = diff.Lines[i];
|
2024-03-17 18:37:06 -07:00
|
|
|
if (line.Type == Models.TextDiffLineType.Added || line.Type == Models.TextDiffLineType.Deleted)
|
|
|
|
{
|
2024-02-28 02:15:40 -08:00
|
|
|
rs.HasLeftChanges = true;
|
|
|
|
break;
|
2024-02-27 05:13:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 02:15:40 -08:00
|
|
|
return rs;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|