Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public string NewCommentText

private readonly Dictionary<string, FileDiffListItemViewModel> _fileDiffLookup = new(StringComparer.OrdinalIgnoreCase);
private readonly SemaphoreSlim _diffLoadSemaphore = new(1, 1);
private CancellationTokenSource? _diffLoadCancellation;

// Total metrics properties for overview section
private int _filesChanged;
Expand Down Expand Up @@ -622,18 +621,6 @@ await Dispatcher.UIThread.InvokeAsync(() =>
}
}

public CancellationToken BeginDiffContentLoad()
{
var oldCts = Interlocked.Exchange(ref _diffLoadCancellation, new CancellationTokenSource());
if (oldCts != null)
{
try { oldCts.Cancel(); } catch { }
oldCts.Dispose();
}

return _diffLoadCancellation.Token;
}

private ReviewModels.FileDiff BuildDiffContent(FileDiffListItemViewModel listItem)
{
var fileDiff = new ReviewModels.FileDiff(listItem.FilePath, listItem.Diff, listItem.OldText, listItem.NewText);
Expand Down
16 changes: 12 additions & 4 deletions AzurePrOps/AzurePrOps/Views/PullRequestDetailsWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private async Task CreateDiffViewerAsync(Expander expander, FileDiffListItemView
return;

// First, show loading placeholder on UI thread
var diffContainer = expander.FindDescendantOfType<Border>();
var diffContainer = FindDiffContainer(expander);
if (diffContainer != null)
{
var loadingText = new TextBlock
Expand All @@ -341,7 +341,7 @@ private async Task CreateDiffViewerAsync(Expander expander, FileDiffListItemView
if (DataContext is not PullRequestDetailsWindowViewModel vm)
return;

var loadToken = vm.BeginDiffContentLoad();
var loadToken = _expansionCancellation?.Token ?? CancellationToken.None;
await vm.EnsureDiffContentLoadedAsync(diff.FilePath, loadToken);
if (loadToken.IsCancellationRequested)
return;
Expand Down Expand Up @@ -377,8 +377,8 @@ private async Task CreateDiffViewerAsync(Expander expander, FileDiffListItemView
// Log error if needed

// Show error on UI thread
var diffContainer = expander.FindDescendantOfType<Border>();
if (diffContainer?.Child is not TextBlock)
var diffContainer = FindDiffContainer(expander);
if (diffContainer is { Child: not TextBlock })
{
var errorText = new TextBlock
{
Expand All @@ -393,6 +393,14 @@ private async Task CreateDiffViewerAsync(Expander expander, FileDiffListItemView
}
}

private static Border? FindDiffContainer(Expander expander)
{
return expander
.GetVisualDescendants()
.OfType<Border>()
.FirstOrDefault(border => string.Equals(border.Name, "DiffContainer", StringComparison.Ordinal));
}

private void ViewInIDE_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (sender is Control btn && btn.DataContext is FileDiffListItemViewModel diff)
Expand Down