Skip to content

Commit

Permalink
Fixed bookmarks assignment/processing issue for Xaml files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey M committed Aug 10, 2020
1 parent d7b6b0c commit f3e1a12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions DPackRx/Extensions/TextBufferExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Projection;

namespace DPackRx.Extensions
{
Expand All @@ -11,6 +12,27 @@ public static class TextBufferExtensions
/// Custom: returns <typeparamref name="T"/> service from the text buffer.
/// </summary>
public static T GetService<T>(this ITextBuffer textBuffer)
{
T service = TryGetService<T>(textBuffer);
if (service != null)
return service;

if (textBuffer is IProjectionBufferBase projectionBuffer)
{
foreach (ITextBuffer sourceTextBuffer in projectionBuffer.SourceBuffers)
{
service = TryGetService<T>(sourceTextBuffer);
if (service != null)
return service;
}
}

return default;
}

#region Private Methods

private static T TryGetService<T>(this ITextBuffer textBuffer)
{
T service = default;
var result = textBuffer.Properties?.TryGetProperty(typeof(T), out service);
Expand All @@ -19,5 +41,7 @@ public static T GetService<T>(this ITextBuffer textBuffer)
else
return default;
}

#endregion
}
}
6 changes: 5 additions & 1 deletion DPackRx/Features/Bookmarks/BookmarksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void RegisterCallback(IBookmarkCallbackClient client, string fileName)

if (_bookmarkCallbacks.ContainsKey(fileName) || _bookmarkCallbacks.ContainsValue(client))
{
_log.LogMessage("Callback client has already been registered", LOG_CATEGORY);
_log.LogMessage($"Callback client has already been registered: {Path.GetFileName(fileName)}", LOG_CATEGORY);
return;
}

Expand Down Expand Up @@ -251,7 +251,11 @@ public bool GoToBookmark(int number)
return false;

if (!_bookmarks.ContainsKey(fileName))
{
_shellStatusBarService.SetStatusBarText($"Bookmark {number} not found");
_log.LogMessage($"Bookmark # {number} is not found", LOG_CATEGORY);
return false;
}

_log.LogMessage($"Looking for '{fileName}' bookmark # {number}", LOG_CATEGORY);
var bookmarks = _bookmarks[fileName];
Expand Down

0 comments on commit f3e1a12

Please sign in to comment.