Skip to content

Commit 28d3209

Browse files
committed
fix: Fix refresh documents that are above the line threshold
1 parent c8aa9c9 commit 28d3209

6 files changed

+24
-16
lines changed

CodeNav.Shared/CodeNavMargin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public void Dispose()
265265
_control.CaretPositionChangedSubscription?.Dispose();
266266
_control.TextContentChangedSubscription?.Dispose();
267267
_control.UpdateWhileTypingSubscription?.Dispose();
268-
_control.FileActionOccuredSubscription?.Dispose();
268+
_control.FileActionOccurredSubscription?.Dispose();
269269

270270
GC.SuppressFinalize(this);
271271
_isDisposed = true;

CodeNav.Shared/CodeViewUserControl.xaml.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public partial class CodeViewUserControl : ICodeViewUserControl
2727
public IDisposable? CaretPositionChangedSubscription { get; set; }
2828
public IDisposable? TextContentChangedSubscription { get; set; }
2929
public IDisposable? UpdateWhileTypingSubscription { get; set; }
30-
public IDisposable? FileActionOccuredSubscription { get; set; }
30+
public IDisposable? FileActionOccurredSubscription { get; set; }
3131

3232
public CodeDocumentViewModel CodeDocumentViewModel { get; set; }
3333

3434
public CodeViewUserControl(ColumnDefinition? column = null)
3535
{
3636
InitializeComponent();
3737

38-
// Setup viewmodel as datacontext
38+
// Setup view model as data context
3939
CodeDocumentViewModel = new CodeDocumentViewModel();
4040
DataContext = CodeDocumentViewModel;
4141

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

5656
// Subscribe to Document save events
57-
if (document != null && FileActionOccuredSubscription == null)
57+
if (document != null && FileActionOccurredSubscription == null)
5858
{
59-
FileActionOccuredSubscription = Observable
59+
FileActionOccurredSubscription = Observable
6060
.FromEventPattern<TextDocumentFileActionEventArgs>(
6161
h => document.FileActionOccurred += h,
6262
h => document.FileActionOccurred -= h)
@@ -185,9 +185,10 @@ public void FilterBookmarks()
185185
public void ToggleAll(bool isExpanded, List<CodeItem>? root = null)
186186
=> OutliningHelper.ToggleAll(root ?? CodeDocumentViewModel.CodeDocument, isExpanded);
187187

188-
public void UpdateDocument(string filePath = "")
188+
/// <inheritdoc/>
189+
public void UpdateDocument(string filePath = "", bool force = false)
189190
=> ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel,
190-
_column, null, filePath));
191+
_column, null, filePath, force));
191192

192193
public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor)
193194
=> HighlightHelper.HighlightCurrentItem(

CodeNav.Shared/CodeViewUserControlTop.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public partial class CodeViewUserControlTop : ICodeViewUserControl
2222
public IDisposable? CaretPositionChangedSubscription { get; set; }
2323
public IDisposable? TextContentChangedSubscription { get; set; }
2424
public IDisposable? UpdateWhileTypingSubscription { get; set; }
25-
public IDisposable? FileActionOccuredSubscription { get; set; }
25+
public IDisposable? FileActionOccurredSubscription { get; set; }
2626

2727
public CodeDocumentViewModel CodeDocumentViewModel { get; set; }
2828

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

58-
public void UpdateDocument(string filePath = "")
58+
/// <inheritdoc/>
59+
public void UpdateDocument(string filePath = "", bool force = false)
5960
=> ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel,
60-
null, _row, filePath));
61+
null, _row, filePath, force));
6162

6263
public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor)
6364
{

CodeNav.Shared/Controls/MainToolbar.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public MainToolbar()
2121
}
2222

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

2626
private void ButtonSortByFileOrder_OnClick(object sender, RoutedEventArgs e)
2727
=> Sort(SortOrderEnum.SortByFile).FireAndForget();

CodeNav.Shared/Helpers/DocumentHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ public static async Task UpdateDocument(ICodeViewUserControl control,
231231
CodeDocumentViewModel codeDocumentViewModel,
232232
ColumnDefinition? column = null,
233233
RowDefinition? row = null,
234-
string filePath = "")
234+
string filePath = "",
235+
bool force = false)
235236
{
236237
if (string.IsNullOrEmpty(filePath))
237238
{
@@ -242,7 +243,7 @@ public static async Task UpdateDocument(ICodeViewUserControl control,
242243

243244
try
244245
{
245-
if (await IsLargeDocument())
246+
if (await IsLargeDocument() && !force)
246247
{
247248
codeDocumentViewModel.CodeDocument = PlaceholderHelper.CreateLineThresholdPassedItem();
248249
return;
@@ -270,7 +271,7 @@ public static async Task UpdateDocument(ICodeViewUserControl control,
270271
codeDocumentViewModel.SortOrder = (SortOrderEnum)general.SortOrder;
271272
SortHelper.Sort(items, (SortOrderEnum)general.SortOrder);
272273

273-
// Set the new list of codeitems as DataContext
274+
// Set the new list of code items as DataContext
274275
codeDocumentViewModel.CodeDocument = items;
275276

276277
// Apply highlights

CodeNav.Shared/ICodeViewUserControl.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ public interface ICodeViewUserControl
1414
{
1515
CodeDocumentViewModel CodeDocumentViewModel { get; set; }
1616

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

1924
void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor);
2025

@@ -30,6 +35,6 @@ public interface ICodeViewUserControl
3035

3136
IDisposable? UpdateWhileTypingSubscription { get; set; }
3237

33-
IDisposable? FileActionOccuredSubscription { get; set; }
38+
IDisposable? FileActionOccurredSubscription { get; set; }
3439
}
3540
}

0 commit comments

Comments
 (0)