Skip to content

Commit

Permalink
Navigation from CodeNav to the code position is imprecise. #121
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir L. Boulema committed Sep 10, 2021
1 parent 9577723 commit 2dbda4d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CodeNav.Shared/CodeNavMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void RegisterEvents()
private void WindowEvents_ActiveFrameChanged(ActiveFrameChangeEventArgs obj)
=> WindowChangedEvent(obj).FireAndForget();

private void DocumentEvents_Saved(object sender, string e)
private void DocumentEvents_Saved(string e)
=> UpdateDocument().FireAndForget();

private async Task WindowChangedEvent(ActiveFrameChangeEventArgs obj)
Expand Down
4 changes: 3 additions & 1 deletion CodeNav.Shared/Helpers/DocumentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public static async Task ScrollToLine(LinePosition linePosition)
{
var documentView = await VS.Documents.GetActiveDocumentViewAsync();
var line = documentView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(linePosition.Line);
documentView?.TextView?.ViewScroller.EnsureSpanVisible(line.Extent);

documentView?.TextView?.Selection.Select(line.Extent, false);
documentView?.TextView?.ViewScroller.EnsureSpanVisible(line.Extent, EnsureSpanVisibleOptions.AlwaysCenter);
}
catch (Exception)
{
Expand Down
39 changes: 25 additions & 14 deletions CodeNav.Shared/Helpers/SettingsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CodeNav.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

Expand All @@ -24,20 +25,7 @@ public static bool UseXMLComments
private static ObservableCollection<FilterRule> _filterRules;
public static ObservableCollection<FilterRule> FilterRules
{
get
{
if (_filterRules == null)
{
_filterRules = JsonConvert.DeserializeObject<ObservableCollection<FilterRule>>(General.Instance.FilterRules);
}

if (_filterRules == null)
{
_filterRules = new ObservableCollection<FilterRule>();
}

return _filterRules;
}
get => LoadFilterRules();
set => _filterRules = value;
}

Expand All @@ -52,5 +40,28 @@ public static void Refresh()
_useXmlComments = null;
_filterRules = null;
}

private static ObservableCollection<FilterRule> LoadFilterRules()
{
if (_filterRules != null)
{
return _filterRules;
}

try
{
_filterRules = JsonConvert.DeserializeObject<ObservableCollection<FilterRule>>(General.Instance.FilterRules);
}
catch (Exception)
{
// Ignore error while loading filter rules
}
finally
{
_filterRules = new ObservableCollection<FilterRule>();
}

return _filterRules;
}
}
}
8 changes: 4 additions & 4 deletions CodeNav.Shared/Helpers/SolutionStorageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static async Task<T> Load<T>()
{
try
{
var solution = await VS.Solution.GetCurrentSolutionAsync();
var solutionFilePath = solution.FileName;
var solution = await VS.Solutions.GetCurrentSolutionAsync();
var solutionFilePath = solution.FullPath;

if (!File.Exists(solutionFilePath))
{
Expand Down Expand Up @@ -52,8 +52,8 @@ public static async Task<T> Load<T>()

public static async Task Save<T>(T storage)
{
var solution = await VS.Solution.GetCurrentSolutionAsync();
var solutionFilePath = solution.FileName;
var solution = await VS.Solutions.GetCurrentSolutionAsync();
var solutionFilePath = solution.FullPath;

if (!File.Exists(solutionFilePath))
{
Expand Down
4 changes: 2 additions & 2 deletions CodeNav.Shared/ToolWindow/CodeNavToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ private void RegisterEvents()
private void WindowEvents_ActiveFrameChanged(ActiveFrameChangeEventArgs obj)
=> WindowEvents_WindowActivated(obj).FireAndForget();

private void DocumentEvents_Opened(object sender, string e)
private void DocumentEvents_Opened(string e)
=> UpdateDocument();

private void DocumentEvents_Saved(object sender, string e)
private void DocumentEvents_Saved(string e)
=> UpdateDocument();

private void OutliningManager_RegionsCollapsed(object sender, RegionsCollapsedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion CodeNav.VS2019/CodeNav.VS2019.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.Toolkit">
<Version>15.0.75.165-pre</Version>
<Version>15.0.76.280-pre</Version>
</PackageReference>
<PackageReference Include="Community.VisualStudio.VSCT">
<Version>16.0.29.6</Version>
Expand Down
4 changes: 2 additions & 2 deletions CodeNav.VS2022/CodeNav.VS2022.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.Toolkit">
<Version>17.0.75.165-pre</Version>
<Version>17.0.76.280-pre</Version>
</PackageReference>
<PackageReference Include="Community.VisualStudio.VSCT">
<Version>16.0.29.6</Version>
Expand All @@ -165,7 +165,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>17.0.4182-preview4</Version>
<Version>17.0.4201-preview4</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 2dbda4d

Please sign in to comment.