Skip to content

Commit

Permalink
Various updates
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
madskristensen committed Sep 23, 2022
1 parent b2478ca commit 0d44865
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
Binary file modified art/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified art/options2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/Commands/ToggleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[Command(PackageIds.Toggle)]
public class ToggleCommand : BaseCommand<ToggleCommand>
{
protected override Task InitializeCompletedAsync()
protected override void BeforeQueryStatus(EventArgs e)
{
Command.Supported = false;
return base.InitializeCompletedAsync();
Command.Checked = General.Instance.Enabled;
}

protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
General settings = await General.GetLiveInstanceAsync();
Expand Down
7 changes: 1 addition & 6 deletions src/Options/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ public class General : BaseOptionModel<General>, IRatingConfig
[DisplayName("Enable rainbow braces")]
[Description("Allows you to toggle the rainbow braces on and off.")]
[DefaultValue(true)]
[Browsable(false)]
public bool Enabled { get; set; } = true;

[Category("General")]
[DisplayName("Max line length")]
[Description("Maximum line count for files to enable colorization. For performance reasons, we don't want to colorize huge files")]
[DefaultValue(3000)]
public int MaxBufferLines { get; set; } = 3000;

[Category("General")]
[DisplayName("Timeout (milliseconds)")]
[Description("Controls the debounce timeout.")]
Expand Down
2 changes: 2 additions & 0 deletions src/RainbowBracesPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using Task = System.Threading.Tasks.Task;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio;

namespace RainbowBraces
{
Expand All @@ -12,6 +13,7 @@ namespace RainbowBraces
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), "Environment\\Fonts and Colors", Vsix.Name, 0, 0, true, SupportsProfiles = true, ProvidesLocalizedCategoryName = false)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(PackageGuids.RainbowBracesString)]
[ProvideAutoLoad(VSConstants.VsEditorFactoryGuid.TextEditor_string, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class RainbowBracesPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
Expand Down
11 changes: 7 additions & 4 deletions src/Tagger/RainbowTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace RainbowBraces
{
public class RainbowTagger : ITagger<IClassificationTag>
{
private const int _maxLineLength = 10000;
private const int _overflow = 500;

private static bool _ratingCounted;
private readonly ITextBuffer _buffer;
private readonly ITextDocument _document;
Expand Down Expand Up @@ -112,14 +115,14 @@ public async Task ParseAsync(int topPosition = 0)
// Must be performed on the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

if (_buffer.CurrentSnapshot.LineCount > options.MaxBufferLines)
if (_buffer.CurrentSnapshot.LineCount > _maxLineLength)
{
await VS.StatusBar.ShowMessageAsync($"No rainbow braces. File too big ({_buffer.CurrentSnapshot.LineCount} lines).");
return;
}

int visibleStart = _view.TextViewLines.First().Start.Position;
int visibleEnd = _view.TextViewLines.Last().End.Position;
int visibleStart = Math.Max(_view.TextViewLines.First().Start.Position - _overflow, 0);
int visibleEnd = Math.Min(_view.TextViewLines.Last().End.Position + _overflow, _buffer.CurrentSnapshot.Length);

ITextSnapshotLine changedLine = _buffer.CurrentSnapshot.GetLineFromPosition(topPosition);

Expand All @@ -146,7 +149,7 @@ public async Task ParseAsync(int topPosition = 0)

foreach (ITextSnapshotLine line in _buffer.CurrentSnapshot.Lines)
{
if ((topPosition > 10 && line.End < visibleStart) || line.Extent.IsEmpty)
if ((line.End < visibleStart) || line.Extent.IsEmpty)
{
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions src/VSCommandTable.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This file was generated by VSIX Synchronizer
// Available from https://marketplace.visualstudio.com/items?itemName=MadsKristensen.VsixSynchronizer64
// </auto-generated>
// ------------------------------------------------------------------------------
namespace RainbowBraces
{
using System;

/// <summary>
/// Helper class that exposes all GUIDs used across VS Package.
/// </summary>
Expand All @@ -15,11 +16,12 @@ internal sealed partial class PackageGuids
public const string RainbowBracesString = "8eb8a1e7-610c-47ec-b867-a8b500937f99";
public static Guid RainbowBraces = new Guid(RainbowBracesString);
}

/// <summary>
/// Helper class that encapsulates all CommandIDs uses across VS Package.
/// </summary>
internal sealed partial class PackageIds
{
public const int Toggle = 0x000A;
}
}
}
2 changes: 1 addition & 1 deletion src/VSCommandTable.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Parent guid="VSEditor" id="Edit.LanguageInfoGroup.Advanced.CommandsGroup"/>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Toggle Rainbow Braces</ButtonText>
<ButtonText>Show Rainbow Braces</ButtonText>
<LocCanonicalName>.RainbowBraces.ToggleOnOff</LocCanonicalName>
</Strings>
</Button>
Expand Down

0 comments on commit 0d44865

Please sign in to comment.