├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── ShowSelectionLength.sln ├── appveyor.yml ├── art └── statusbar.png └── src ├── CommandHandler.cs ├── Properties └── AssemblyInfo.cs ├── Resources └── Icon.png ├── ShowSelectionLength.csproj ├── ShowSelectionLengthPackage.cs ├── source.extension.cs └── source.extension.vsixmanifest /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | 3 | # User files 4 | *.suo 5 | *.user 6 | *.sln.docstates 7 | .vs/ 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Rr]elease/ 12 | x64/ 13 | [Bb]in/ 14 | [Oo]bj/ 15 | 16 | # MSTest test Results 17 | [Tt]est[Rr]esult*/ 18 | [Bb]uild[Ll]og.* 19 | 20 | # NCrunch 21 | *.ncrunchsolution 22 | *.ncrunchproject 23 | _NCrunch_WebCompiler -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Mads Kristensen 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Show Selection Length 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/5v7xuu075fctgagv?svg=true)](https://ci.appveyor.com/project/madskristensen/showselectionlength) 4 | 5 | Download this extension from the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ShowSelectionLength) 6 | or get the [CI build](http://vsixgallery.com/extension/c2ffcafd-dc47-4a4f-ba6b-07bcd6f2b0b6/). 7 | 8 | --------------------------------------- 9 | 10 | When selecting text in the Visual Studio editor, this extension shows the number of charcters in the selected range - including invisible characters such as `/r` and `/n`. 11 | 12 | ![Status bar](art/statusbar.png) 13 | 14 | ## License 15 | [Apache 2.0](LICENSE) -------------------------------------------------------------------------------- /ShowSelectionLength.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29118.113 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShowSelectionLength", "src\ShowSelectionLength.csproj", "{48833570-3A2C-450D-8EEE-C348E09FA2E8}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EEAD86FC-E8B8-4700-A316-5065A3BD443F}" 9 | ProjectSection(SolutionItems) = preProject 10 | appveyor.yml = appveyor.yml 11 | README.md = README.md 12 | EndProjectSection 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {48833570-3A2C-450D-8EEE-C348E09FA2E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {48833570-3A2C-450D-8EEE-C348E09FA2E8}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {48833570-3A2C-450D-8EEE-C348E09FA2E8}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {48833570-3A2C-450D-8EEE-C348E09FA2E8}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {C847AA0F-5FD8-4B53-A84A-D4C8770A4070} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2019 2 | 3 | install: 4 | - ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex 5 | 6 | before_build: 7 | - ps: Vsix-IncrementVsixVersion | Vsix-UpdateBuildVersion 8 | - ps: Vsix-TokenReplacement src\source.extension.cs 'Version = "([0-9\\.]+)"' 'Version = "{version}"' 9 | 10 | build_script: 11 | - nuget restore -Verbosity quiet 12 | - msbuild /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m 13 | 14 | after_test: 15 | - ps: Vsix-PushArtifacts | Vsix-PublishToGallery 16 | -------------------------------------------------------------------------------- /art/statusbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/ShowSelectionLength/458e0fbaa5e8bdadf8285969bd35d68f6753460c/art/statusbar.png -------------------------------------------------------------------------------- /src/CommandHandler.cs: -------------------------------------------------------------------------------- 1 | using Community.VisualStudio.Toolkit; 2 | using Microsoft.VisualStudio.Shell; 3 | using Microsoft.VisualStudio.Text; 4 | using Microsoft.VisualStudio.Text.Editor; 5 | using Microsoft.VisualStudio.Utilities; 6 | using System; 7 | using System.ComponentModel.Composition; 8 | using System.Linq; 9 | 10 | namespace ShowSelectionLength 11 | { 12 | [Export(typeof(IWpfTextViewCreationListener))] 13 | [ContentType("text")] 14 | [TextViewRole(PredefinedTextViewRoles.PrimaryDocument)] 15 | public class CommandHandler : WpfTextViewCreationListener 16 | { 17 | protected override void Created(DocumentView docView) 18 | { 19 | docView.TextView.Selection.SelectionChanged += SelectionChanged; 20 | } 21 | 22 | protected override void Closed(IWpfTextView textView) 23 | { 24 | textView.Selection.SelectionChanged -= SelectionChanged; 25 | } 26 | 27 | private void SelectionChanged(object sender, EventArgs e) 28 | { 29 | ThreadHelper.JoinableTaskFactory.RunAsync(async delegate 30 | { 31 | var selection = (ITextSelection)sender; 32 | 33 | if (selection.IsEmpty) 34 | { 35 | await VS.StatusBar.ClearAsync(); 36 | 37 | return; 38 | } 39 | 40 | var length = 0; 41 | var linesCount = 0; 42 | var lastLine = -1; 43 | 44 | foreach (SnapshotSpan snapshotSpan in selection.SelectedSpans) 45 | { 46 | length += snapshotSpan.Length; 47 | var snapshot = snapshotSpan.Snapshot; 48 | var startLine = snapshot.GetLineNumberFromPosition(snapshotSpan.Start); 49 | var endLine = snapshot.GetLineNumberFromPosition(snapshotSpan.End); 50 | 51 | linesCount += endLine - startLine; 52 | // if previous selection was not on the same line as start of this selection add 1 else the line will be counted twice 53 | if (lastLine != startLine) linesCount++; 54 | lastLine = endLine; 55 | } 56 | 57 | if (length > 0) 58 | { 59 | await VS.StatusBar.ShowMessageAsync($"Selection Ln: {linesCount} Ch: {length}"); 60 | } 61 | 62 | }).FireAndForget(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using ShowSelectionLength; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle(Vsix.Name)] 6 | [assembly: AssemblyDescription(Vsix.Description)] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany(Vsix.Author)] 9 | [assembly: AssemblyProduct(Vsix.Name)] 10 | [assembly: AssemblyCopyright(Vsix.Author)] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: AssemblyVersion(Vsix.Version)] 17 | [assembly: AssemblyFileVersion(Vsix.Version)] 18 | -------------------------------------------------------------------------------- /src/Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/ShowSelectionLength/458e0fbaa5e8bdadf8285969bd35d68f6753460c/src/Resources/Icon.png -------------------------------------------------------------------------------- /src/ShowSelectionLength.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 16.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | Debug 10 | AnyCPU 11 | 2.0 12 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | {48833570-3A2C-450D-8EEE-C348E09FA2E8} 14 | Library 15 | Properties 16 | ShowSelectionLength 17 | ShowSelectionLength 18 | v4.7.2 19 | true 20 | true 21 | true 22 | true 23 | false 24 | true 25 | true 26 | Program 27 | $(DevEnvDir)devenv.exe 28 | /rootsuffix Exp 29 | 30 | 31 | true 32 | full 33 | false 34 | bin\Debug\ 35 | DEBUG;TRACE 36 | prompt 37 | 4 38 | 39 | 40 | pdbonly 41 | true 42 | bin\Release\ 43 | TRACE 44 | prompt 45 | 4 46 | 47 | 48 | 49 | 50 | 51 | 52 | True 53 | True 54 | source.extension.vsixmanifest 55 | 56 | 57 | 58 | 59 | Resources\LICENSE 60 | true 61 | 62 | 63 | Designer 64 | VsixManifestGenerator 65 | source.extension.cs 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 16.0.76.303 75 | 76 | 77 | runtime; build; native; contentfiles; analyzers; buildtransitive 78 | all 79 | 80 | 81 | 82 | 83 | true 84 | 85 | 86 | 87 | 88 | 95 | -------------------------------------------------------------------------------- /src/ShowSelectionLengthPackage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Shell; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace ShowSelectionLength 6 | { 7 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] 8 | [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)] 9 | [Guid("0631cfcf-d450-4bc4-be4e-bfad0101f9c2")] 10 | public sealed class ShowSelectionLengthPackage : AsyncPackage 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/source.extension.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace ShowSelectionLength 7 | { 8 | internal sealed partial class Vsix 9 | { 10 | public const string Id = "c2ffcafd-dc47-4a4f-ba6b-07bcd6f2b0b6"; 11 | public const string Name = "Show Selection Length"; 12 | public const string Description = @"Shows the length of the editor text selection in the status bar"; 13 | public const string Language = "en-US"; 14 | public const string Version = "1.0.9993"; 15 | public const string Author = "Mads Kristensen"; 16 | public const string Tags = "selection, editor"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Show Selection Length 6 | Shows the length of the editor text selection in the status bar 7 | https://github.com/madskristensen/ShowSelectionLength 8 | Resources\LICENSE 9 | Resources\Icon.png 10 | Resources\Icon.png 11 | selection, editor 12 | 13 | 14 | 15 | 16 | amd64 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | --------------------------------------------------------------------------------