Skip to content

Commit

Permalink
fix: Fix refresh documents that are above the line threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Feb 5, 2025
1 parent c8aa9c9 commit 28d3209
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CodeNav.Shared/CodeNavMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void Dispose()
_control.CaretPositionChangedSubscription?.Dispose();
_control.TextContentChangedSubscription?.Dispose();
_control.UpdateWhileTypingSubscription?.Dispose();
_control.FileActionOccuredSubscription?.Dispose();
_control.FileActionOccurredSubscription?.Dispose();

GC.SuppressFinalize(this);
_isDisposed = true;
Expand Down
13 changes: 7 additions & 6 deletions CodeNav.Shared/CodeViewUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public partial class CodeViewUserControl : ICodeViewUserControl
public IDisposable? CaretPositionChangedSubscription { get; set; }
public IDisposable? TextContentChangedSubscription { get; set; }
public IDisposable? UpdateWhileTypingSubscription { get; set; }
public IDisposable? FileActionOccuredSubscription { get; set; }
public IDisposable? FileActionOccurredSubscription { get; set; }

public CodeDocumentViewModel CodeDocumentViewModel { get; set; }

public CodeViewUserControl(ColumnDefinition? column = null)
{
InitializeComponent();

// Setup viewmodel as datacontext
// Setup view model as data context
CodeDocumentViewModel = new CodeDocumentViewModel();
DataContext = CodeDocumentViewModel;

Expand All @@ -54,9 +54,9 @@ public async Task RegisterDocumentEvents()
var textBuffer2 = documentView?.TextView?.TextBuffer as ITextBuffer2;

// Subscribe to Document save events
if (document != null && FileActionOccuredSubscription == null)
if (document != null && FileActionOccurredSubscription == null)
{
FileActionOccuredSubscription = Observable
FileActionOccurredSubscription = Observable
.FromEventPattern<TextDocumentFileActionEventArgs>(
h => document.FileActionOccurred += h,
h => document.FileActionOccurred -= h)
Expand Down Expand Up @@ -185,9 +185,10 @@ public void FilterBookmarks()
public void ToggleAll(bool isExpanded, List<CodeItem>? root = null)
=> OutliningHelper.ToggleAll(root ?? CodeDocumentViewModel.CodeDocument, isExpanded);

public void UpdateDocument(string filePath = "")
/// <inheritdoc/>
public void UpdateDocument(string filePath = "", bool force = false)
=> ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel,
_column, null, filePath));
_column, null, filePath, force));

public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor)
=> HighlightHelper.HighlightCurrentItem(
Expand Down
7 changes: 4 additions & 3 deletions CodeNav.Shared/CodeViewUserControlTop.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class CodeViewUserControlTop : ICodeViewUserControl
public IDisposable? CaretPositionChangedSubscription { get; set; }
public IDisposable? TextContentChangedSubscription { get; set; }
public IDisposable? UpdateWhileTypingSubscription { get; set; }
public IDisposable? FileActionOccuredSubscription { get; set; }
public IDisposable? FileActionOccurredSubscription { get; set; }

public CodeDocumentViewModel CodeDocumentViewModel { get; set; }

Expand Down Expand Up @@ -55,9 +55,10 @@ public void ToggleAll(bool isExpanded, List<CodeItem>? root = null)
OutliningHelper.ToggleAll(root ?? CodeDocumentViewModel.CodeDocument, isExpanded);
}

public void UpdateDocument(string filePath = "")
/// <inheritdoc/>
public void UpdateDocument(string filePath = "", bool force = false)
=> ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel,
null, _row, filePath));
null, _row, filePath, force));

public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor)
{
Expand Down
2 changes: 1 addition & 1 deletion CodeNav.Shared/Controls/MainToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MainToolbar()
}

private void ButtonRefresh_OnClick(object sender, RoutedEventArgs e)
=> WpfHelper.FindParent(this)?.UpdateDocument();
=> WpfHelper.FindParent(this)?.UpdateDocument(force: true);

private void ButtonSortByFileOrder_OnClick(object sender, RoutedEventArgs e)
=> Sort(SortOrderEnum.SortByFile).FireAndForget();
Expand Down
7 changes: 4 additions & 3 deletions CodeNav.Shared/Helpers/DocumentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public static async Task UpdateDocument(ICodeViewUserControl control,
CodeDocumentViewModel codeDocumentViewModel,
ColumnDefinition? column = null,
RowDefinition? row = null,
string filePath = "")
string filePath = "",
bool force = false)
{
if (string.IsNullOrEmpty(filePath))
{
Expand All @@ -242,7 +243,7 @@ public static async Task UpdateDocument(ICodeViewUserControl control,

try
{
if (await IsLargeDocument())
if (await IsLargeDocument() && !force)
{
codeDocumentViewModel.CodeDocument = PlaceholderHelper.CreateLineThresholdPassedItem();
return;
Expand Down Expand Up @@ -270,7 +271,7 @@ public static async Task UpdateDocument(ICodeViewUserControl control,
codeDocumentViewModel.SortOrder = (SortOrderEnum)general.SortOrder;
SortHelper.Sort(items, (SortOrderEnum)general.SortOrder);

// Set the new list of codeitems as DataContext
// Set the new list of code items as DataContext
codeDocumentViewModel.CodeDocument = items;

// Apply highlights
Expand Down
9 changes: 7 additions & 2 deletions CodeNav.Shared/ICodeViewUserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public interface ICodeViewUserControl
{
CodeDocumentViewModel CodeDocumentViewModel { get; set; }

void UpdateDocument(string filePath = "");
/// <summary>
/// Update the Code Document View Model
/// </summary>
/// <param name="filePath">Optional path to use as code source file</param>
/// <param name="force">Optional boolean to indicate to update documents that may contain too many lines</param>
void UpdateDocument(string filePath = "", bool force = false);

void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor);

Expand All @@ -30,6 +35,6 @@ public interface ICodeViewUserControl

IDisposable? UpdateWhileTypingSubscription { get; set; }

IDisposable? FileActionOccuredSubscription { get; set; }
IDisposable? FileActionOccurredSubscription { get; set; }
}
}

0 comments on commit 28d3209

Please sign in to comment.